I am trying to use jQuery to do a simple thing: clear the input fields of a group of input field within a div whenever the form loads, or if the user changes a picklist; but
This function is used to clear all the elements in the form including radio button, check-box, select, multiple select, password, text, textarea, file.
function clear_form_elements(class_name) {
jQuery("."+class_name).find(':input').each(function() {
switch(this.type) {
case 'password':
case 'text':
case 'textarea':
case 'file':
case 'select-one':
case 'select-multiple':
case 'date':
case 'number':
case 'tel':
case 'email':
jQuery(this).val('');
break;
case 'checkbox':
case 'radio':
this.checked = false;
break;
}
});
}
Change this:
<div class=fetch_results>
To this:
<div id="fetch_results">
Then the following should work:
$("#fetch_results input").each(function() {
this.value = "";
})
http://jsfiddle.net/NVqeR/
Just had to delete all inputs within a div & using the colon in front of the input when targeting gets most everything.
$('#divId').find(':input').val('');