Thursday, May 23, 2024
 Popular · Latest · Hot · Upcoming
44
rated 0 times [  47] [ 3]  / answers: 1 / hits: 55710  / 12 Years ago, mon, march 19, 2012, 12:00:00

Say we have 2 different select boxes with the same number of options:



<select id=box1>
<option value=1 >1</option>
<option value=2 >2</option>
</select>

<select id=box2>
<option value=3 >3</option>
<option value=4 >4</option>
</select>


Is it possible when we select the first box to select the same option number in the second box automatically? Without jQuery if possible.



UPDATE: the values of 2 boxes are different! When we select the first value of box1 the box 2's value will automatically would be 3! and so on...


More From » dom

 Answers
14

Yes. Add an onChange property to the first select, then use it to call a javascript function you have written elsewhere.



<select id=box1 onChange=changeBox2(this.selectedIndex);>
<option value=1 >1</option>
<option value=2 >2</option>
</select>

<select id=box2>
<option value=1 >1</option>
<option value=2 >2</option>
</select>


W3 Schools JavaScript Events



Example on Accessing SELECT properties in JS


[#86758] Saturday, March 17, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
brockg

Total Points: 55
Total Questions: 104
Total Answers: 104

Location: Hungary
Member since Wed, Nov 9, 2022
2 Years ago
;