Posted By

digitalclubb on 12/15/10


Tagged

input jquery function


Versions (?)

jQuery function to clear inputs


 / Published in: jQuery
 

Simply run the function when the document has loaded and specify setDefault to true.

  1. function initInput(setDefault) {
  2.  
  3. var inputValues = {};
  4.  
  5. if (setDefault == null) setDefault = false;
  6.  
  7. $('input:text, input:password').each(function() {
  8. if (setDefault) inputValues['' + $(this).attr('id') + ''] = $(this).val();
  9.  
  10. $(this).focus(function() {
  11. if ($(this).val() == inputValues[$(this).attr('id')]) $(this).val('');
  12. });
  13.  
  14. $(this).blur(function() {
  15. if ($(this).val() == '') $(this).val(inputValues[$(this).attr('id')]);
  16. });
  17.  
  18. });
  19.  
  20. }

Report this snippet  

You need to login to post a comment.