By arunraj
To clear all form fields in jquery use the following code.
$.fn.clearForm = function() {
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if(this.disabled==true)
return;
if (tag == 'form')
return $(':input',this).clearForm();
if (type == 'text' || type == 'password' || tag == 'textarea')
{
this.value = '';
}
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = 0;
});
};
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if(this.disabled==true)
return;
if (tag == 'form')
return $(':input',this).clearForm();
if (type == 'text' || type == 'password' || tag == 'textarea')
{
this.value = '';
}
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = 0;
});
};