473,395 Members | 1,526 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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 3552
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

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

Similar topics

1
by: Greg Scharlemann | last post by:
I would like to automatically populate a drop down menu when the page loads based on the selection of an item in a different drop down menu. I made a test page that when drop down #1 changes, drop...
2
by: juglesh | last post by:
hi, all, thanks for reading. i have a form in which i want drop down boxes to dynamically change some hidden fields: http://cynthialoganjewelry.com/test4.htm <form name=test method="post" > ...
5
by: Elvis V. | last post by:
Good morning, I have a table with three fields, Buildings, Floors and Rooms. This is what I would like to do; in my form when I select Building1 in my drop down box for Buildings, when I go to the...
2
by: Phil Longworth | last post by:
Im very new to Access 97 and Im sure I should be able to do this but cant work out how. Im bulding a database for my stamp collection. I have two tables; one with details of all the individual...
19
by: nazgulero | last post by:
Hello all, I wonder if anybody can give me a hint about what I have to do to get this working: I am creating a drop down box using the script below. The result is two text fields; now I want...
1
by: Per | last post by:
Hi, I have a problem that I can't figure out. I have a database application to keep track of boxes that contain files. For data entry, I have a form with a main form section for the box-specific...
1
by: azeemqaiser | last post by:
Hi All, I have a form with two drop down controls. I want to change the values of Drop Down Menu 2 if i select some value in Drop Down Menu 1. Like If i select country then all the states of...
4
by: gotonagle | last post by:
hi , i m new to asp and leraning it... i have only one page in which i take some values like name, dob and education degree. after post back i return to this page iteslf.. but the values in...
3
by: ghjk | last post by:
i have two drop down boxes and when user select District from 1st drop down box , the cityis in that district should load to the second drop down. My code is below. But it is not working. Please...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.