Forum Moderators: open

Message Too Old, No Replies

How can I make "Enter Search Term Here" dissapear on click?

         

cy182

3:16 pm on Aug 2, 2007 (gmt 0)

10+ Year Member



Hello,
I have a search engine that searches my website and it says Enter Search Term Here on (or in?) the search engine. Is there any way the text can disspear when someone clicks on it instead of erasing the text? I'm a noob to web design so any help is appreciated.

WesleyC

3:43 pm on Aug 2, 2007 (gmt 0)

10+ Year Member



On the <input> field, add onclick="this.value='';".

cy182

3:53 pm on Aug 2, 2007 (gmt 0)

10+ Year Member



Wow, that was surprisingly easy! Thanks WesleyC!

WesleyC

4:00 pm on Aug 2, 2007 (gmt 0)

10+ Year Member



Some things are amazingly easy with Javascript. :)

Fotiman

4:56 pm on Aug 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Careful... that will also delete whatever the user types in. For example, user types in "webmaster world" and then switches focus and then wants to change the search to "webmaster world javascript". When the user clicks in the text box, the previous text will be wiped out.

Better alternatives would be to have your onclick handler first check to see if the value of the text box is "Enter Search Term Here" before wiping it out. However, this approach (as well as the original suggestion) has an accessibility issue. For accessibility reasons, the label for the text box should preceed the text box, so that someone who is blind or using a screen reader knows what the text box is for before getting to it. One method that I read about at A List Apart called "Making Compact Forms More Accessible" does what you're looking for and still remains accessible. (unfortunately, I can not post the link here).

[edited by: Fotiman at 4:57 pm (utc) on Aug. 2, 2007]

cy182

10:51 pm on Aug 2, 2007 (gmt 0)

10+ Year Member



Thanks for the info Fotiman, but the website I am working on can't really be used by blind people anyways (videos).