Clear Form Data


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



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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.