Forum Moderators: open

Message Too Old, No Replies

Text field value in different color

Text field one color for initial value and another for user input

         

Nando

9:41 pm on Nov 19, 2006 (gmt 0)

10+ Year Member



Hi folks

My text fields have a value which is "Please list".

Using onFocus, this value disappears when the user clicks inside the textbox and is replaced by whatever the user inputs

i.e: onFocus="if (value == 'please list') {value=''}"

However, it would be nice if the initial value of "Please list" were in a grey colored font so as to appear faint BUT when the user inputed their stuff, it was black.

I can get it to always be grey or black or whatever color but not one color for the initial value and another for the user input and done in a simple way without calling any complicated functions.

Any ideas?

Cheers
nando

RonPK

8:59 am on Nov 20, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can simply change the value of the style attribute:
<input  
type="text"
value="please list"
style="color: #ccc;"
onfocus="if (this.value == 'please list') {this.value=''; this.style.color='#000';}"
>

Nando

6:58 pm on Nov 20, 2006 (gmt 0)

10+ Year Member



Works perfectly.

Thanks very much Ron :)