jQuery form reset button for all entered values
Won't the <input type="reset" >
suffice?
<form>
<input type='reset' />
</form>
DEMO
The other jQuery solution for resetting the form fields would be:
$('#form')[0].reset(); or $('#form').get(0).reset();
Another one, more specific, referring to the required fields:
$('#form').find('input, select').not(':button, :submit, :reset, :hidden').val('').removeAttr('checked').removeAttr('selected');
jsFiddle Working Live Demo - jQuery Solution
Using only JavaScript:
document.getElementById('form').reset();
Using only HTML:
As it was mentioned in one of the answers, in most cases you don't need JavaScript for resetting the form fields, it works just by settings type="reset"
to the button, e.g.:
<button type="reset" value="Reset">Reset</button>
Try the following:
$(function() {
$('#reset').click(function() {
$(':input','#myform')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
});
});
You're running the javascript before the DOM is ready. $(function() {})
only runs when the DOM is ready. Read more here: .ready()