I am trying to clear only specific ID input field on my checkbox click. I am switching two fieldset on checkbox click and I want to clear specific ID fields from click on checkbox from all fieldset.
I got this script but its clearing everything from my form and that’s what not I am looking but only specific ID fields.
function clear_form_elements(ele) {
$(ele).find(':input').each(function() {
switch(this.type) {
case 'text':
case 'textarea':
$(this).val('');
break;
this.checked = false;
}
});
}
I’m not sure what your form structure looks like, but if you want to clear text, textarea, checkbox, or select values by id you could use
Assuming:
if ‘#id’ is unique throughout your site, or your javascript is page-specific, Nick’s method will work fine.