Posted By

spraitas on 10/14/10


Tagged

form jquery


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

mattvbiggs
Tyster


Clear form data


 / Published in: jQuery
 

  1. $.fn.clearForm = function() {
  2. // iterate each matching form
  3. return this.each(function() {
  4. // iterate the elements within the form
  5. $(':input', this).each(function() {
  6. var type = this.type, tag = this.tagName.toLowerCase();
  7. if (type == 'text' || type == 'password' || tag == 'textarea' || type == 'hidden')
  8. this.value = '';
  9. else if (type == 'checkbox' || type == 'radio')
  10. this.checked = false;
  11. else if (tag == 'select')
  12. this.selectedIndex = -1;
  13. });
  14. });
  15. };

Report this snippet  

You need to login to post a comment.