469,318 Members | 1,937 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,318 developers. It's quick & easy.

Automatically change values in a drop down select box in a form

Hello All

I need some help in a form i'm creating. I have to fields with drop down select boxes. What i want to do is, when a user selects a given value in one drop down, the other drop down should atumatically change to another value.

Ex: the user choses the number "4" in one box, then the other box should change to "4 WD".

Here is my code:

[HTML]<select name="job___num_layers" onChange="document.getElementById('parray_div').st yle.display=(this.selectedIndex>1)?'block':'none'; ">
<option value="2" selected="selected">2</option>
<option value="4">4</option>
<option value="6">6</option>
<option value="10">10</option>
<option value="14">14</option>
<option value="18">18</option>
</select>

<select name="job___num_layers">
<option value="3WD" selected="selected">3 WD (Standard)</option>
<option value="4WD">4 WD (standard)</option>
<option value="5WD">5 WD (standard)</option>
<option value="7WD">7 WD (standard)</option>
<option value="8WD">8 WD (standard)</option>
<option value="9WD">9 WD (standard)</option>
</select>[/HTML]
Feb 19 '08 #1
3 3346
acoder
16,027 Expert Mod 8TB
Do the values which have to be set have the same selectedIndex as the first drop down? If they do, just use the selectedIndex, e.g. secondSelect.selectedIndex = firstSelect.selectedIndex. Put this in a function and call it onchange of the first drop down. I assume you know how to access elements within the page.
Feb 19 '08 #2
Do the values which have to be set have the same selectedIndex as the first drop down? If they do, just use the selectedIndex, e.g. secondSelect.selectedIndex = firstSelect.selectedIndex. Put this in a function and call it onchange of the first drop down. I assume you know how to access elements within the page.
Could you post an example of what you mean...??? They do not have the same selectedIndex. The selectedIndex that is used on the first drop down is unique for that drop down, and has nothing to do with the second drop down.
Feb 19 '08 #3
acoder
16,027 Expert Mod 8TB
Could you post an example of what you mean...??? They do not have the same selectedIndex. The selectedIndex that is used on the first drop down is unique for that drop down, and has nothing to do with the second drop down.
I meant them matching up, e.g. the option with value 4 has a selectedIndex of 1 which is also the selectedIndex of "4WD" in the second drop down. Anyway, if they don't match up, use the value instead and use an array like the following:
Expand|Select|Wrap|Line Numbers
  1. var arr = {"4":"4WD","6":"5WD","10":"7WD"};
  2. document.getElementById(secondSelectID).value = arr[val]; //val is value of 1st drop down
to match them.
Feb 19 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Greg Scharlemann | last post: by
2 posts views Thread by juglesh | last post: by
19 posts views Thread by nazgulero | last post: by
3 posts views Thread by ghjk | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by harlem98 | last post: by
reply views Thread by listenups61195 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.