How To Control Text Inside Search Forms


I discovered a new site today that has a very similar to approach to www.onetipady.com. Daily Blog Tips does what it says on the tin. Everyday a useful tip is given for bloggers.

I found the site while I was looking for a solution to something on this site that has been bothering me. I wanted to customise my search entry forms so that text would be displayed giving helpful instructions to users, that would disappear when they clicked in the box, without them having to delete it.

Luckily Daniel has given some very clear instructions on how to do this.

First off you need to find the code that controls your searchform. It should look something like this:

< input name="s" id="s" size="20" type="text" />

Now you will need to add three new arguments inside that line:

* value=”Text to be displayed here”
* onfocus=”if(this.value==this.defaultValue)this.value=’’;”
* onblur=”if(this.value==’’)this.value=this.defaultValue;”

The last two arguments are the two magical ones that make sure that the text you inserted will disappear once the user clicks on the input area, and also that it will reappear if the user clicks somewhere else.

By adding these two lines of code to your search form you will get the desired result, and your final line of code will look like this:

< input type="text" name="s" id="s" value="Text to be displayed here" onfocus="if(this.value==this.defaultValue)this.value='';" onblur="if(this.value=='')this.value=this.defaultValue;"/>

Bookmark & Share

Post Info

About the Author

author photo

Want to get more out of your PC, the internet or your mp3 player? Onetipaday.com is here to provide clear simple tips and guides to help you achieve just that. Each tip will be easy to implement and will take no more than 5 minutes to read and implement. What will you learn today?

See All Posts by This Author

2 Responses to “How To Control Text Inside Search Forms”

  1. Daniel says:

    thanks for picking this, i am also grabbing your tips, i mean feed!

Trackbacks/Pingbacks

  1. Craisin.com | Craisin.com Revamp - Spring 2009!

Subscribe without commenting

Leave a Reply

CommentLuv Enabled
Comment Policy: Any comments are permitted only because the site owner is letting you post, and any comments could be removed for any reason at the absolute discretion of the site owner.