homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Search Field
Text In Form

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

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)


<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)

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)

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='';">

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved