Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Form values that disappear on click



5:28 am on Aug 10, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

You know those search forms that have something like "Enter your text here" as an initial value in them, then you click in the field, and the text disappears.
How is that done? I assume it's java, but I guess it could be css. Either way, how do you do it?


11:37 am on Aug 10, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member

see [webmasterworld.com...] for JavaScript solution ( java is something completely different ). Not aware of css solution.


2:21 pm on Aug 10, 2012 (gmt 0)

5+ Year Member

Try this.

<input type="text" onblur="if (this.value=='') { this.value='Please enter your text'; }" onfocus="if (this.value=='Please enter your text') { this.value=''; }" value="Please enter your text" id="search" name="search">


3:18 pm on Aug 10, 2012 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month

HTML5 has added a "placeholder" attribute, so you don't need any scripting for this at all.

Internet Explorer 9 or earlier doesn't support this, so you'd still need a JavaScript solution for those cases.

Featured Threads

Hot Threads This Week

Hot Threads This Month