JQuery reset or clear large form
How can you clear or reset large fields of form quickly.You can use jquery $('#formID').reset();. But this would remain in the form if you reset it this way.This is why a “manual” reset is needed.
This is the perfect way to clear large or small or any form using jquery.
$(':input','#YourFormID')
.not(':button, :submit, :reset, :hidden')
.val('')
.removeAttr('checked')
.removeAttr('selected');
Also you can use following function and call to it for clear the form by passing form ID or name as parameter.
function resetForm($form) {
$form.find('input:text, input:password, input:file, select, textarea').val('');
$form.find('input:radio, input:checkbox')
.removeAttr('checked').removeAttr('selected');
}
// How to call:
resetForm($('#YourFormID')); // by id, recommended
resetForm($('form[name=myName]')); // by name
You can use following simple method to clear form.
// Use a whitelist of fields to minimize unintended side effects.
$('INPUT:text, INPUT:password, INPUT:file, SELECT, TEXTAREA', '#myFormId').val('');
// De-select any checkboxes, radios and drop-down menus
$('INPUT:checkbox, INPUT:radio', '#myFormId').removeAttr('checked').removeAttr('selected');
What's your reaction?
Excited
0
Happy
0
In Love
0
Not Sure
0
Silly
0





