Clear values of all form elements using jQuery
Hello friends,
I always wanted to have one common function to reset all form elements. Please have a look at jQuery code that does the same thing. It finds out all element of form and loops over it and reset them. I hope this thing will be helpful specifically where there are many search fields and you need to reset them frequently.
function resetFormElements(frm){
$(frm).find(':input').each(function() {
switch(this.type){
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
$(this).val('');
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
});
}
Note : I noticed that some time in IE selectbox is not getting cleared. So you can modify script and put
'$(this).attr("selectedIndex",0);' for 'select-one' case. It will work in both IE and mozilla.

Recent Comments