Created
June 17, 2010 04:26
-
-
Save coryschires/441687 to your computer and use it in GitHub Desktop.
plugin to clear form form data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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