Posted By

Jamie on 12/24/10


Tagged

search default input text field


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

maltem


Clear Text Field of its default value, and return the original value


 / Published in: JavaScript
 

  1. // A simple, lightweight, on-the-fly script to handle the clearing and resetting of a text field
  2. var searchField = document.getElementById('search');
  3. var defaultText = searchField.value;
  4. searchField.onfocus = function(){
  5. if( searchField.value == defaultText ){
  6. searchField.value = '';
  7. }
  8. };
  9. searchField.onblur = function(){
  10. if( searchField.value == '' ){
  11. searchField.value = defaultText;
  12. }
  13. };

Report this snippet  

You need to login to post a comment.