i came up with this code that will validate a select box based on a class attribute. however, i need to cycle or loop through all select boxes no matter how many are generated (based on the class attribute). the following code only validates the first select box. any help would be greatly appreciated.
function validateUser(form) {
if ((form.elements[0].className =="Test" && (form.elements[0].value =="Select an item")
{
alert("You must select a reason"
return false;
}
else {return true;}
}
</script>
<TR><TD COLSPAN=3><select class="Test" name="dropDown">
<OPTION value="Select an item">Select an item</OPTION>
<OPTION value="Acceptable">Acceptable</OPTION>
<OPTION value="Repair">Repair</OPTION>
<OPTION value="Replace">Replace</OPTION>
<OPTION value="Unacceptable">Unacceptable</OPTION>
</SELECT></TD></TR>
<TR><TD COLSPAN=3><select class="Test" name="dropDown2">
<OPTION value="Select an item">Select an item</OPTION>
<OPTION value="Accept">Accept</OPTION>
<OPTION value="Replace">Replace</OPTION>
</SELECT></TD></TR>
<TR><TD COLSPAN=3><TABLE>
<INPUT type="submit" value="Submit" ONCLICK="return validateUser(document.forms[0])" name="Submit">
function validateUser(form) {
if ((form.elements[0].className =="Test" && (form.elements[0].value =="Select an item")
{
alert("You must select a reason"
return false;
}
else {return true;}
}
</script>
<TR><TD COLSPAN=3><select class="Test" name="dropDown">
<OPTION value="Select an item">Select an item</OPTION>
<OPTION value="Acceptable">Acceptable</OPTION>
<OPTION value="Repair">Repair</OPTION>
<OPTION value="Replace">Replace</OPTION>
<OPTION value="Unacceptable">Unacceptable</OPTION>
</SELECT></TD></TR>
<TR><TD COLSPAN=3><select class="Test" name="dropDown2">
<OPTION value="Select an item">Select an item</OPTION>
<OPTION value="Accept">Accept</OPTION>
<OPTION value="Replace">Replace</OPTION>
</SELECT></TD></TR>
<TR><TD COLSPAN=3><TABLE>
<INPUT type="submit" value="Submit" ONCLICK="return validateUser(document.forms[0])" name="Submit">