Posted By

jonkemp on 06/25/10


Tagged

javascript jquery


Versions (?)

Clear Text Field on Focus


 / Published in: JavaScript
 

This requires jQuery. The script checks to see if default text is present in a text field on focus. If it is, then it clears the text. Otherwise, it leaves user entered text intact. This is normally used for a search box.

  1. $("#searchbox").focus(function () {
  2. if ($("#searchbox").val() == "Blah Blah Blah") {
  3. $("#searchbox").val("");
  4. }
  5. });

Report this snippet  

You need to login to post a comment.