How to reset a form programmatically?

I want to reset the form in a jQuery click event function. How to do it?

+5
source share
5 answers

It has the simplest: $("form-selector-here")[0].reset()but also see: Resetting a multi-stage form using jQuery

Note that this does not require jQuery at all, as it $(selector)[0]gets the original DOM element. You can also say document.getElementById("myFormId").reset().

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

    // OR
    document.getElementById("form1").reset();
});​​​
+13
source

This should work:

$("#formid")[0].reset();
+1
source

try it

$('#FormID').each (function(){
this.reset();
});
+1
source

you can do it like this:

$(function(){
    $('#resetForm').click(function(){
        $('form input[type=text]').val('');});
});

jsfiddle

0
source

add this at the end of the form:

<div style="display='none';" ><input type="reset" id="rst_form"></div>

and try the following:

$('#rst_form').click()
0
source

All Articles