pheromix
pheromix

Reputation: 19307

How to reset a form programmatically?

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

Upvotes: 8

Views: 3326

Answers (5)

mattematico
mattematico

Reputation: 669

you could do it like this:

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

jsfiddle

Upvotes: 0

Sergiu
Sergiu

Reputation: 73

add this at the end of the form:

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

and try this:

$('#rst_form').click()

Upvotes: 0

Tim M.
Tim M.

Reputation: 54377

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();
});​​​

Upvotes: 14

beNerd
beNerd

Reputation: 3374

try this

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

Upvotes: 1

Jim Garrison
Jim Garrison

Reputation: 4276

This should work:

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

Upvotes: 1

Related Questions