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.
Simply use the
jQuery Trigger event
like so:This will reset checkboxes, radiobuttons, textboxes, etc... Essentially it turns your form to it's default state. Simply put the
#ID, Class, element
inside thejQuery
selector.Here with the refresh for checkboxes and selects:
All these answers are good but the absolute easiest way of doing it is with a fake reset, that is you use a link and a reset button.
Just add some CSS to hide your real reset button.
And then on your link you add as follows
Hope this helps! A.
I'm using Paolo Bergantino solution which is great but with few tweaks... Specifically to work with the form name instead an id.
For example:
Now when I want to use it a could do
As you see, this work with any form, and because I'm using a css style to create the button the page will not refresh when clicked. Once again thanks Paolo for your input. The only problem is if I have defaults values in the form.
There's a big problem with Paolo's accepted answer. Consider:
The
.val('')
line will also clear anyvalue
'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:
I'm just an intermediate in PHP, and a bit lazy to dive into a new language like JQuery, but isn't the following a simple and elegant solution?
Can't see a reason why not have two submit buttons, just with different purposes. Then simply:
You just redefine your values back to whatever the default is supposed to be.