How to .reset() form with jQuery

Such jQuery call won’t work:

1
2
	$('#formId').reset();
	// error: $("#formId").reset() is not a function

As the tutorial shows (yes, I never read manuals before I get into troubles as well, but always google answers before think, lol), we can have the following:

1
2
3
4
5
function resetForm(id) {
	$('#'+id).each(function(){
	        this.reset();
	});
}

…and somewhere on a page this:

1
	<input type="button" onclick="resetForm('formId');" />

This entry was posted on Saturday, November 22nd, 2008 at 04:56 and is filed under jQuery. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.





9 Responses to “How to .reset() form with jQuery”

Wha-ha! Just use

$(’#myFormId’)[0].reset();

“$(’#myFormId’)[0].reset();”

Thanks Konstantin, easy solution

this doesnt work..
someone please help…

add this at the end of the form

and try this,
$(’#rst_form’).click()

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()

DownsTream

Thanks…

easy solution but it work!!!

Bruno Soares

only this:

$(’form’)[0].reset();

get the form element…. and not the specific form directly: (’#myform’)

it work => $(’#myform’)[0].reset()
Thanks for the idea

Thanks a lot for a good idea.

Leave a Reply


required


required (will not be published)



CAPTCHA image