I want to clear all input and textarea fields in a form. It works like the following when using an input button with the reset
class:
$(\".reset
I got easiest trick to reset form
jQuery("#review-form")[0].reset();
or
$("#review-form").get().reset();
Why you dont use document.getElementById("myId").reset();
? this is the simple and pretty
For jQuery 1.6+:
$(':input','#myform')
.not(':button, :submit, :reset, :hidden')
.val('')
.prop('checked', false)
.prop('selected', false);
For jQuery < 1.6:
$(':input','#myform')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
Please see this post: Resetting a multi-stage form with jQuery
Or
$('#myform')[0].reset();
As jQuery suggests:
To retrieve and change DOM properties such as the
checked
,selected
, ordisabled
state of form elements, use the .prop() method.
If someone is still reading this thread, here is the simplest solution using not jQuery, but plain JavaScript. If your input fields are inside a form, there is a simple JavaScript reset command:
document.getElementById("myform").reset();
More about it here: http://www.w3schools.com/jsref/met_form_reset.asp
Cheers!
Use this Code Where you want to Call Normal Reset Function by jQuery
setTimeout("reset_form()",2000);
And Write this Function Out Site jQuery on Document Ready
<script>
function reset_form()
{
var fm=document.getElementById('form1');
fm.reset();
}
</script>
This won't handle cases where form input fields have non empty default values.
Something like should work
$('yourdiv').find('form')[0].reset();