I want to create an onload function. This function must reset the values in a form to "All".I came across this script. The problem that I have it clears all the values to blank.
}
function Reset() {
document.forms[0].elements[0].value = "";
document.forms[0].elements[1].value = "";
document.forms[0].elements[2].value = "";
document.forms[0].elements[3].value = "";
document.forms[0].elements[4].value = "";
document.forms[0].elements[5].value = "";
document.forms[0].elements[6].value = "";
document.forms[0].elements[7].value = "";
document.forms[0].elements[0].focus();
}
When I change the "" to "All" it only changes the first fields value to "All". The first field is a text field and the rest of the fields are option select fields. Is there a way that I can change the values of the select fields to All using the above script ?
It's a bit different with option selects, you can't just set a value with a string like that. You have to set the selectedIndex property the index of your "All" item within the select box. IE:
In that example, the index of "All" is 0 (indicies always start at zero, so the first "bleh" would be index 1). To change it, I'd use:
Code:
document.forms[0].elements[0].selectedIndex = 0;
Hope that helps.
__________________ Please login or register to view this content. Registration is FREE - Latest Articles: Please login or register to view this content. Registration is FREE , Please login or register to view this content. Registration is FREE