/ Published in: jQuery
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/* ------------------------------------------------------------------ Clears the form data -------------------------------------------- */ $.fn.clearForm = function() { return this.each(function() { $(".error", this).removeClass("error"); $('input,select,textarea', this).clearFields(); }); }; // Clears the selected form elements. $.fn.clearFields = $.fn.clearInputs = function() { return this.each(function() { var t = this.type, tag = this.tagName.toLowerCase(); if (t == 'text' || t == 'password' || tag == 'textarea') this.value = ''; else if (t == 'checkbox' || t == 'radio') this.checked = false; else if (tag == 'select') this.selectedIndex = 0; }); };