I have a form with a standard reset button coded thusly:
<input type="reset" class="button standard" value="Clear" />
Trouble is, said form is of the multi-stage sort, so if a user fills out a stage & then returns later, the 'remembered' values for the various fields won't reset when the Clear button is clicked.
I'm thinking that attaching a jQuery function to loop over all the fields and clear them 'manually' would do the trick. I'm already using jQuery within the form, but am only just getting up to speed & so am not sure how to go about this, other than individually referencing each field by ID, which doesn't seem very efficient.
TIA for any help.
basically none of the provided solutions makes me happy. as pointed out by a few people they empty the form instead of resetting it.
however, there are a few javascript properties that help out:
these store the value that a field had when the page was loaded.
writing a jQuery plugin is now trivial: (for the impatient... here's a demo http://jsfiddle.net/kritzikratzi/N8fEF/1/)
plugin-code
usage
some notes ...
$( "#container" ).resetValue()
won't work. always use$( "#container :input" )
instead.here is my solution, which also works with the new html5 input-types:
Paolo's answer doesn't account for date pickers, add this in:
Here is something to get you started
Of course, if you have checkboxes/radio buttons, you'll need to modify this to include them as well and set
.attr({'checked': false});
edit Paolo's answer is more concise. My answer is more wordy because I did not know about the
:input
selector, nor did I think about simply removing the checked attribute.I used the solution below and it worked for me (mixing traditional javascript with jQuery)