Thursday, February 23, 2012

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:

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

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

Similar Articles

  1. A simple “Share on Facebook” link
  2. How to Create a Multi-link Javascript Jump Box
  3. Ten Important SEO Tips
  4. Style Sheet Switcher Script
  5. Image Rotation Script in PHP
  6. Simple Website Redirections
  7. WordPress Popular Snippets

Hosting Encyclopedia