Clear Text Box When Clicking on It

If you have a text box on your webpage (eg – a search form) with text in it (eg – “Search…”), it adds an extra level of convenience for your user if the text box clears when the user clicks inside the box. This is achieved with some simple javascript:

<input onclick="this.value='';" name="Search" type="text" value="Search..." />

The crucial part is onclick=”this.value=”;” – whenever the text box is clicked on, it sets the text box’s value to empty.

If you want, you could have the box automatically refilled with the same text or different text with this simple addition to the above code.

onblur="if (this.value == '') {this.value = 'your email';

You may have already noticed the Search form and Email Subscription form are configured this way. Try it out.

Tweet This Post

SocialTwist Tell-a-Friend

1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 4.00 out of 5)
Loading ... Loading ...

Comments

  1. confucius on March 10th, 2009

    I’ve always wondered how to do that, lol…thanks!

  2. Admin on March 10th, 2009

    you’re welcome!

  3. traderblog on April 4th, 2009

    little things like this sometimes make users experience alot funner. :-)

  4. J on April 9th, 2009

    how do you do the on click effect for a one time deal. If you have not noticed if a person clicks on the text box area again after entering information it is erased. I just want it on the initial click that’s all???

  5. Admin on April 10th, 2009

    then leave the following part out.

    onblur=”if (this.value == ”) {this.value = ‘your email’;

Leave a Reply




CommentLuv Enabled

Free Email Subscription

Poll

21 Free Random Links

Have a new site and want to show off and get linked? Send us an email and we'll link it here for free.