Clear Text Field on Focus


/ Published in: JavaScript
Save to your folder(s)

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.


Copy this code and paste it in your HTML
  1. $("#searchbox").focus(function () {
  2. if ($("#searchbox").val() == "Blah Blah Blah") {
  3. $("#searchbox").val("");
  4. }
  5. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.