How to clear a text field on click and also change it's color

Viewed 56

I have a search text box with an initial value of "Search" and a gray color.

When it is clicked, I want to clear the text and set the color to black so when the User stats typing, it is in black.

I have this so far and it clears fine. I tried to add a css style to it but its gives me a syntax error: the attribute is missing the attribute name following the namespace.

 onfocus="if(this.value == 'Search') { this.value = ''; }" onblur="if(this.value == '') { this.value = 'Search'; }"

 onfocus="if(this.value == 'Search') { this.value = ''; style="color: #000000;"; }" onblur="if(this.value == '') { this.value = 'Search'; }"
2 Answers
Related