Reputation: 19307
I want to reset a form in a JQuery click event function. How to do that ?
Upvotes: 8
Views: 3326
Reputation: 669
you could do it like this:
$(function(){
$('#resetForm').click(function(){
$('form input[type=text]').val('');});
});
Upvotes: 0
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
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