Forum Moderators: open

Message Too Old, No Replies

change selected index of drop down box

how is it possible to change the default index of a drop down box

         

Superbuis1

7:58 pm on Apr 15, 2004 (gmt 0)

10+ Year Member



Hello,

I have 2 drop down boxes. The both contain the same date information. What I want is that if the user changes the date in the first drop down box, the same date should be selected in the second drop down box. If figured out that I get the selected index with:
"sel=document.forms[0].date1.options[document.forms[0].Date1.selectedIndex].index".
But how can I give this value to the second drop down box? Is there a method like:
"return document.forms[0].Date2.options[document.forms[0].Date2.setIndex].index = sel"
or something similar? Or is it only possible that I sent both arrays (date1 and date2) to my Javascript when I run it? How should I do this in this case? (Sorry, I'm rather new to Javascript :))

Thanks!

Alternative Future

8:10 pm on Apr 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Superbuis1,

Is it something like this you are looking for?

<html>
<head>
</head>
<body>
<select id=sel1 onchange="document.getElementById('sel2').value=this.value">
<option>Please Select</option>
<option value="Date 1">Date 1</option>
<option value="Date 2">Date 2</option>
</select><br>
<select id=sel2>
<option>Please Select</option>
<option value="Date 1">Date 1</option>
<option value="Date 2">Date 2</option>
</select>
</body>
</html>

HTH,

-George

Superbuis1

6:55 am on Apr 16, 2004 (gmt 0)

10+ Year Member



Thanks George! This was what I was looking for. I didn't think of the id property. Good, simple and nice solution :)