Posted By

touffies on 12/15/10


Tagged

form jquery


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

virendrakryadav


Clear Form Data


 / Published in: jQuery
 

  1. /* ------------------------------------------------------------------
  2.   Clears the form data -------------------------------------------- */
  3. $.fn.clearForm = function() {
  4. return this.each(function() {
  5. $(".error", this).removeClass("error");
  6. $('input,select,textarea', this).clearFields();
  7. });
  8. };
  9.  
  10. // Clears the selected form elements.
  11. $.fn.clearFields = $.fn.clearInputs = function() {
  12. return this.each(function() {
  13. var t = this.type, tag = this.tagName.toLowerCase();
  14. if (t == 'text' || t == 'password' || tag == 'textarea')
  15. this.value = '';
  16. else if (t == 'checkbox' || t == 'radio')
  17. this.checked = false;
  18. else if (tag == 'select')
  19. this.selectedIndex = 0;
  20. });
  21. };

Report this snippet  

You need to login to post a comment.