views:

86

answers:

3

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=''" />
+3  A: 

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'; }"> 
Daniel Vassallo
+3  A: 

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.

Chibu
A: 

Going off @chibu's answer, this is how you would do it using jQuery and unobtrusive Javascript


 
$(document).ready(
   function() {
      $("#mytext").bind(
         "click",
         function() {
            $(this).val("");
            $(this).css("color", "red");
         }
      );
   }
)


Levi Hackwith
@Levi Hackwith i don't know jQuery at all. could you give me some links, where i can study it?
Syom
Gladly!- http://jquery.com/- http://www.learningjquery.com/
Levi Hackwith