8

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

pheromix
  • 18,213
  • 29
  • 88
  • 158

5 Answers5

14

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();
});​​​
Community
  • 1
  • 1
Tim M.
  • 53,671
  • 14
  • 120
  • 163
  • 1
    The accepted answer to that question is just setting the input fields to blank, but a true reset sets all input fields to their original value. – David Hedlund Sep 07 '12 at 07:07
  • I think the answers to that question collectively cover the important scenarios, though? – Tim M. Sep 07 '12 at 07:09
1

This should work:

$("#formid")[0].reset();
Jim Garrison
  • 4,199
  • 4
  • 25
  • 39
1

try this

$('#FormID').each (function(){
this.reset();
});
beNerd
  • 3,314
  • 6
  • 54
  • 92
0

you could do it like this:

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

jsfiddle

Dirty-flow
  • 2,306
  • 11
  • 30
  • 49
mattematico
  • 669
  • 3
  • 14
0

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()
will-hart
  • 3,742
  • 2
  • 38
  • 48
Sergiu
  • 73
  • 7