Reset a form
<script type="text/javascript" charset="utf-8">
function resetForm(form) {
$(form).find('input:text, input:password, input:file, select, textarea').val('');
$(form).find('input:radio, input:checkbox').removeAttr('checked').removeAttr('selected');
}
</script>
Written by Jonathan Goode
Related protips
2 Responses
There is also javascript's native form .reset() method:
- document.forms["myForm"].reset();
- - or -
document.getElementById("myFormId").reset();
over 1 year ago
·
You'd use my function if you already had a populated form where textboxes had values and checkboxes were checked (with the attribute set) and you wanted to reset those to be blank and unchecked.
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Jquery
Authors
Related Tags
#jquery
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#