How to clear all inputs, selects and also hidden fields in a form using jQuery?
$('#formID')[0].reset(); // Reset all form fields
To clear all inputs, including hidden fields, using JQuery:
// Behold the power of JQuery.
$('input').val('');
Selects are harder, because they have a fixed list. Do you want to clear that list, or just the selection.
Could be something like
$('option').attr('selected', false);
You can use the reset()
method:
$('#myform')[0].reset();
or without jQuery:
document.getElementById('myform').reset();
where myform
is the id of the form containing the elements you want to be cleared.
You could also use the :input
selector if the fields are not inside a form:
$(':input').val('');