Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
The moose likes HTML, CSS and JavaScript and the fly likes Greying a Textbox Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Greying a Textbox" Watch "Greying a Textbox" New topic

Greying a Textbox

Viralraj Upadhyay

Joined: Nov 10, 2006
Posts: 22
Can I grey a text box using javascript which has no text to prevent a user from entering any text?If yes how? I dont want to disable it. I want to grey it.
Purushoth Thambu
Ranch Hand

Joined: May 24, 2003
Posts: 425
This question has been asked before here. If you are using Firefox all you have to do is make the textbox "readonly", however IE doesn't gray as good as firefox. You have to use CSS to get the desired color. Below is style I applied. Couldn't spend more time to get the border color right.

To change the color on the fly you can create a named style and assign the class attribute of the textbox.

You have more than one way to create gray text box, but you need CSS.
[ March 01, 2007: Message edited by: Purushothaman Thambu ]
I agree. Here's the link:
subject: Greying a Textbox
jQuery in Action, 3rd edition