Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to reset a form programmatically?

Tags:

html

jquery

I want to reset a form in a JQuery click event function. How to do that ?

like image 713
pheromix Avatar asked Sep 07 '12 07:09

pheromix


People also ask

How do I reset a form?

You can easily reset all form values using the HTML button using <input type=”reset”> attribute. Clicking the reset button restores the form to its original state (the default value) before the user started entering values into the fields, selecting radio buttons, checkboxes, etc.

How do you clear a form in JavaScript?

Reset or clear a form using JavaScript, with the reset() method. The reset method sets the values of all elements in a form like clicking the reset button.

How would you reset all objects on a form?

The reset() method resets the values of all elements in a form (same as clicking the Reset button). Tip: Use the submit() method to submit the form.

How do I reset a form in react?

If you use uncontrolled form inputs, an input type of reset will reset the form inputs to their original values. Using controlled inputs, you must set each input state variable value to its default values.


3 Answers

At it's simplest: $("form-selector-here")[0].reset() but also see: Resetting a multi-stage form with jQuery

Note that jQuery isn't necessary for this at all, as $(selector)[0] obtains the original DOM element. You could also say document.getElementById("myFormId").reset().

​$("#btn1").click(function(){
    $("#form1")[0].reset();

    // OR
    document.getElementById("form1").reset();
});​​​
like image 152
Tim M. Avatar answered Oct 12 '22 23:10

Tim M.


This should work:

$("#formid")[0].reset();
like image 23
Jim Garrison Avatar answered Oct 13 '22 00:10

Jim Garrison


try this

$('#FormID').each (function(){
this.reset();
});
like image 44
beNerd Avatar answered Oct 13 '22 00:10

beNerd