Code to Reset/Clear all the controls using JavaScript

Virendradugar
Posted by Virendradugar under JavaScript category on | Views : 6865
This function will reset/clear all the controls of the page.

function ClearAllControls() 
{
for (i=0; i<document.forms[0].length; i++)
{
doc = document.forms[0].elements[i];
switch (doc.type)
{
case "text" :
doc.value = "";
break;
case "textarea" :
doc.value = "";
break;
case "checkbox" :
doc.checked = false;
break;
case "radio" :
doc.checked = false;
break;
case "select-one" :
doc.selectedIndex = 0;
break;
case "select-multiple" :
while (doc.selectedIndex != -1)
{
indx = doc.selectedIndex;
doc.options[indx].selected = false;
}
doc.selected = false;
break;

default :
break;
}
}
}

Comments or Responses

Login to post response