Validating Selection Lists
Selection lists are handled in the same way as other nontext objects using a for loop:
function windowreturn(field1){ myForm=document.forms[0]; for (var i=0; i < myForm.field1.length; i++){ if (myForm.list[i].selected) { choice = true; } } self.close(); }
Here's an example using JavaScript to verify that no more than x number of options are selected in a selection list field:
choices = 0;
for (var i=0; i < field1.length; i++){
if (form.list[i].selected) {
choices++;
}
}
if (choices > 5) {
alert("Sorry you can only pick 5 choices!");
} else {
alert("You picked " + choices + " choices!");
}
Категории