Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Search Field

Text In Form



2:39 pm on May 31, 2005 (gmt 0)

10+ Year Member

Hi All, I know this is fairly simple to accomplish, but I can't remember, and none of my books or web searches have answered my question.

My site has a js search form. I'd like for that form to already have text in it. The end user should be able to search using that pre-defined string, or change the text to something else to search for.

Thanks In Advance,
Chris Leonard


2:46 pm on May 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


<input name="name" type="text" class="textbox" OnBlur="if (this.value=='') this.value='Please enter your name'" value="Please enter your name" size="35" OnActivate="if (this.value=='Please enter your name') this.value='';">

This will bring show a form field with "Please enter your name" as the value. If you click on the field, the text vanishes - if you leave the field without typing anything, "Please enter your name" reappears.

Non JS browsers should see naught.


5:14 pm on Jun 3, 2005 (gmt 0)

10+ Year Member

Okay I'm just now getting back here. I posted this code on my form, and my message only appears when they click OUT of the box. How can I set it so that it appears on the page when they load?

Is this a function of setting the page cursor to this search field?



1:23 am on Jun 4, 2005 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member

The default value loads with the value attribute itself,

<input type="text" name="q" value="Enter Search Here">

To which you can add

<input type="text" name="q" value="Enter Search Here" onFocus="this.value='';">

If it bothers you that this blanks it while tabbing, use onClick

<input type="text" name="q" value="Enter Search Here" onClick="this.value='';">


Featured Threads

Hot Threads This Week

Hot Threads This Month