Skip to content

Instantly share code, notes, and snippets.

@coryschires
Created June 17, 2010 04:26
Show Gist options
  • Save coryschires/441687 to your computer and use it in GitHub Desktop.
Save coryschires/441687 to your computer and use it in GitHub Desktop.
plugin to clear form form data
// tiny plugin to clear form form data.
$.fn.clearForm = function() {
// iterate each matching form
return this.each(function() {
// iterate the elements within the form
$(':input', this).each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = '';
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment