Loop Thru Drop Down boxes....

C

ckerns

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?

Many thanx!

jp
 
R

RobG

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.
 
A

ASM

(e-mail address removed) a écrit :
I have a page with a bunch of drop down boxes.

What is a drop down box ?
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?

#1 or first choice ?
Many thanx!

Sorry but without calling things by their names ...








If you are speaking of elements 'select' of a form and of their selected
'options', (all selects as drop down lists) :

Javascript :

function getSelected(myForm) {
var f = (typeof (myForm) == 'string')?
document.forms[myForm] || document.getElementById(myForm) :
myForm;
var t = '';
for(var i=0; i<f.length; i++) {
if(f.tagName.toLowerCase()=='select') {
t += f.name+' = ';
var k = f.selectedIndex;
if(k==0) t += 'default';
else t += f[k].value;
t += '\n';
}
}
return t;
}

Html :

<a href="#" onclick="alert(getSelected('form_1')); return false;">
form 'form_1' choices</a>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top