I have a page with a bunch of drop down boxes. They are named:
MonEquipAMWk1
MonEquipPMWk1
thru
FriEquipAMWk1
FriEquipPMWk1
(this sequence continues until Wk11)
How do I loop thru these boxes, check their value, & assign an
alternate value if the selection of a box is selection #1?
To loop through the elements, pass a reference to the form to:
function checkSelects(form){
var c1 = ['Wk1','Wk2','Wk3','Wk4','Wk5','Wk6',
'Wk7','Wk8','Wk9','Wk10','Wk11'];
var c2 = ['Mon','Tue','Wed','Thu','Fri'];
var c3 = ['AM','PM'];
var sel;
for (var i=0, len1=c1.length; i<len1; i++){
for (var j=0, len2=c2.length; j<len2; j++){
for (var k=0, len3=c3.length; k<len3; k++){
sel = form.elements[ c2[j] + 'Equip' + c3[k] + c1
];
/* Check the selected option's value or text (or both)
and set the selectedIndex property to whatever
*/
}
}
}
}
A simpler method is to enclose the selects in a div, then use a
reference to the div and getElementsByTagName to get the selects and
loop through them:
function checkSelects(divID){
var div = document.getElementById(divID);
var sel, sels = div.getElementsByTagName('select');
for (var i=0, len=sels.length; i<len; i++){
sel = sels;
/* do stuff with sel as above */
}
}
Feature detection omitted for brevity, don't forget to include it.