Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text color in text field

I have an input text field, which has a value "something" by default, but when I start to type, I want that the default value changes color, and the text i'll type, another one.

How can i do that?


<input type="text" value="something" onclick="this.value=''" />
like image 780
Simon Avatar asked Mar 25 '10 15:03

Simon


2 Answers

To keep it simple like your example:

<input type="text" value="something" onclick="this.value='';this.style.color='red';" />

And that should pretty much do it.

like image 59
Chibu Avatar answered Sep 21 '22 15:09

Chibu


You may want to try the following:

<input type="text" value="something"
       onFocus="if (this.value == 'something') this.style.color = '#ccc';"
       onKeyDown="if (this.value == 'something') {  
                      this.value = ''; this.style.color = '#000'; }"> 
like image 28
Daniel Vassallo Avatar answered Sep 21 '22 15:09

Daniel Vassallo