You can reset your HTMl form to its default values using reset button. But if you have to clear off all the values you need to achieve this through java script.
Refer to following simple java script method:
function clear() {
for (var i=0;i<document.forms[0].elements.length;i++) {
if (document.forms[0].elements[i].type == "text" || document.forms[0].elements[i].type == "textarea")
document.forms[0].elements[i].value = "";
else if (document.forms[0].elements[i].type == "select-one")
document.forms[0].elements[i].selectedIndex = 0;
else if (document.forms[0].elements[i].type == "checkbox")
document.forms[0].elements[i].checked = false;
}
}
for (var i=0;i<document.forms[0].elements.length;i++) {
if (document.forms[0].elements[i].type == "text" || document.forms[0].elements[i].type == "textarea")
document.forms[0].elements[i].value = "";
else if (document.forms[0].elements[i].type == "select-one")
document.forms[0].elements[i].selectedIndex = 0;
else if (document.forms[0].elements[i].type == "checkbox")
document.forms[0].elements[i].checked = false;
}
}
No comments:
Post a Comment