Clever forms

Associate
Joined
19 Jun 2006
Posts
162
Location
Swansea, Wales
In an html form sometimes you get writing already in the form in the text box, for example "search here". When you click on it the writing disappears and you type in an empty box.

Anybody know how to do this?
 
Code:
<input type="text" name="foo" id="foo" value="Search" onfocus="this.value = ( this.value == 'Search' ) ? '' : this.value;" onblur="this.value = ( this.value == '' ) ? 'Search' : this.value" />

(Much better ways of doing this, but this works fine. Replace all instances of "Search" with what you'd like the text to be.
 
Back
Top Bottom