I have a form with a standard reset button coded thusly:
Trouble i
There's a big problem with Paolo's accepted answer. Consider:
$(':input','#myform')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
The .val('') line will also clear any value's assigned to checkboxes and radio buttons. So if (like me) you do something like this:
Using the accepted answer will transform your inputs into:
Oops - I was using that value!
Here's a modified version that will keep your checkbox and radio values:
// Use a whitelist of fields to minimize unintended side effects.
$('INPUT:text, INPUT:password, INPUT:file, SELECT, TEXTAREA', '#myFormId').val('');
// De-select any checkboxes, radios and drop-down menus
$('INPUT:checkbox, INPUT:radio', '#myFormId').removeAttr('checked').removeAttr('selected');