Clear form data


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



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.