473,624 Members | 2,249 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Drop down boxes: show related items in second box on selection in first

21 New Member
hi all,
i had two drop down boxes
on the selection of one item in the first drop down box
the related items should be changed in the second one
can any one please suggest me towards the solution

thanks in advance
kash
Sep 22 '08 #1
10 4815
Rsmastermind
93 New Member
You can see a similar threads where there was 3 different dropdown and the case was similar.
But anyways I am giving you the solution for this.

[HTML]<td><span>Actio n</span></td>
<td><select id="combo1" name="combo2" size="1" class="optional " onchange="chang eCombo2(this);" >
<option value="conditio n 1">condition 1</option>
<option value="conditio n 2">condition 2</option></select></td>

<td><span>No Action</span></td>
<td><select id="combo2" name="combo2" size="1" class="optional " onchange="chang eCombo2(this);" >
<option value="on condition 1">on condition 1</option>
<option value="on condition 2">on condition 2</option></select></td>[/HTML]

Expand|Select|Wrap|Line Numbers
  1. function changeCombo2(that){
  2. var combo2= document.getElementById("combo2");
  3. myobj=combo2.parentNode;//This could vary as per your DOM structure
  4. if (that.value=='condition 1'){
  5. myobj.innerHTML='<select id="combo2" name="combo2" size="1" class="optional" ><option value="no Proceed">no Proceed</option><option value="no reject">no Reject</option></select>';
  6. }
  7. else if(that.value=='condition 2'){
  8. myobj.innerHTML='<select id="combo2" name="combo2" size="1" class="optional" ><option value="Why Proceed">Why Proceed</option><option value="Why reject">Why Reject</option></select>';
  9.  
  10. }
  11. }

In any concern please let me know......
Sep 22 '08 #2
kashhere
21 New Member
hi thanq
but actually

the elements in the first combo box should be constant
for example if i had keep the first combo box as country then i will display the countries list in the first combo box
on selection of particular country i need to display the states under that country in the second drop down

please guide me towards the solution

thank you
kash
Sep 22 '08 #3
kashhere
21 New Member
Hi every one
i need urgent help on drop down boxes

actually i had two drop down boxes
like country and states

when i had selected a country then the respective states should be displayed in the second drop down boxes and when i have selected a particular state in that then the info which is present in a table should be displayed

can any one please suggest me towards the solution
its a bit urgent

thank you
Sep 22 '08 #4
Dormilich
8,658 Recognized Expert Moderator Expert
this depends a bit on where you store all the data. If it's not too much to load, you may hard code it into the script, otherwise (e.g. data stored in a database) you probably should go for ajax.

regards
Sep 22 '08 #5
acoder
16,027 Recognized Expert Moderator MVP
Threads merged. Please do not double post your questions.

Moderator.
Sep 22 '08 #6
kashhere
21 New Member
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. </head>
  4.  
  5. <body>
  6.  
  7. FIRST COMBO BOX:-
  8. -------------------------------
  9.  
  10. <select name="country">
  11. <option selected>---Select1-------------</option>
  12. <option>India</option>
  13. <option>Australia</option>
  14. . . . . . .
  15. </select>
  16.  
  17. SECOND COMBO BOX:-
  18. --------------------------------------
  19.  
  20. Related to first item of first combo
  21. -------------------------------------------------
  22. <select name="state">
  23. <option selected>...select......</option>
  24. <option>Delhi</option>
  25. <option>AP</option>
  26. .........
  27. </select>
  28.  
  29. Related to second item of first combo
  30. ------------------------------------------------------
  31. <select name="state">
  32. <option selected>....select...</option>
  33. <option>California</option>
  34. <option>.....</option>
  35. .......
  36. </select>
  37.  
  38.  
  39.  
  40. <table id="list" style="display:none;">
  41. <tr>
  42. <td>THIS IS SOME INFO</td>
  43. </tr>
  44. </table>
  45.  

Actually what i need is i had 2 r 3 tables which are invisible
when i select one item in the second combo box then the table related to that will be displayed
Means here when i select the option california then the table related to that should be displayed
can any one please guide me towards the solution

thanks in advance
kash
Sep 22 '08 #7
acoder
16,027 Recognized Expert Moderator MVP
kashhere, please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future. Thanks.

Moderator.
Sep 22 '08 #8
kashhere
21 New Member
sry this will not be repeated
next time i will follow your instructins
can you please guide me towards the solution
its a bit urgent

thank you

kash
Sep 23 '08 #9
Rsmastermind
93 New Member
Somehow I had done the mistake I had written id for the both as same.

You just try this code this is tried and executed sucessfully


[HTML]<html><body>
<td><span>Actio n</span></td>
<td><select id="combo1" name="combo1" size="1" class="optional " onchange="chang eCombo2(this);" >
<option value="conditio n 1">Proceed</option>
<option value="conditio n 2">Reject</option></select></td>

<td><span>No Action</span></td>
<td><select id="combo2" name="combo2" size="1" class="optional " >
<option value="conditio n 1">Proceed</option>
<option value="conditio n 2">Reject</option></select></td>

</body></html>[/HTML]
Expand|Select|Wrap|Line Numbers
  1. <script type='text/javascript'>
  2.  
  3. function changeCombo2(that){
  4. var combo2= document.getElementById("combo2");
  5. myobj=combo2.children;//This could vary as per your DOM structure
  6. if (that.value=='condition 1'){
  7. myobj[0].firstChild.nodeValue='no Proceed';
  8. myobj[1].firstChild.nodeValue='no Reject';
  9. }
  10. else if(that.value=='condition 2'){
  11. myobj[0].firstChild.nodeValue='Why Proceed';
  12. myobj[1].firstChild.nodeValue='Why Reject';
  13.  
  14. }
  15. }
  16. </script>
Sep 23 '08 #10

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

Similar topics

6
2458
by: PT | last post by:
I got a form with many text boxes, checkboxes and 3 drop downs. From that 3, 2 are dependant. I can choose one drop down, and the next drop down should display the dependant values of the first drop down chosed. And I have a submite button to submit all these values to DB. First problem: I cant keep the value of the selected text in the first drop down. It always goes back to the first value. (but the asp site extension changes...
4
6294
by: Dan | last post by:
Can anyone offer suggestions on how to do this or if it is possible? I have a form that uses a drop down box and 2 text fields. What I am trying to do is have the value of each text box set by the choice from the drop down box. Something like: <form name="populatefrm" id="contactfrm" method="post"
1
2899
by: Dan | last post by:
This is one that has me stumped and I need an expert's input. Any ideas why the values from the second script-generated drop down list isn't recognized by the script to add time values to the text boxes? What this script is suppose to do is change the value of a second drop down list based on the selection from the first. Then a value is chosen from the script generated drop down list in the
5
6522
by: SirPoonga | last post by:
I think I'd have to do a combination of ASP and javascript to do this. What I want to do fill the first drop down box with values from a database query. Then based off that selection fill in the values of another drop down. Let's use the car industry as an example. Lets say I am storing in a database the data and relationships between car make, car type, and car model. So the first drop down box would like all makes. Upon selecting...
2
9461
by: kmnotes04 | last post by:
Is it possible to link one drop-down box to another? For example, if a name is chosen from a drop-down list, can another drop-down list then automatically display the person's office as a result of the choice made in the first drop-down list? If so, how can that be done? I am working with 'Teach Yourself Microsoft Access' and I didn't see it discussed in that book (if it's even possible to do). Or would I just have to create linked tables...
2
12609
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will select any skill in 1st drop down list then i'll select % of this skill in the 2nd list box , based on the percentage i've selected in the 2nd list box it has to display 2 sets of drop down list boxes at run time one for selecting skill and
5
4219
by: Vigneshwar Pilli via DotNetMonster.com | last post by:
string connectionString1 = "server=(local); user=sa;password=sa; database=sonic"; System.Data.SqlClient.SqlConnection dbConnection1 = new System.Data.SqlClient.SqlConnection(connectionString1); System.Data.SqlClient.SqlCommand dbCommand1 = new System.Data.SqlClient.SqlCommand();
7
2431
by: callawayglfr | last post by:
I am building a database in access where I have a drop down box that relates to a text box, that part I have working but when someone selects information from the first drop down I need it to limit the second drop down to just the related information. Explaining this is obviously challeging. So I'll try to draw a picture: (drop down 1) Select number --- once selected description is populated in text box (drop down 2) based on first...
3
2542
by: amcoldspy | last post by:
Hi, am trying to create dynamic drop down boxes.. there are 3 drop down boxes. The second drop down box elements are to be update based on the selection made in the first drop down box (selecting an element on the first drop down box calls a getData.jsp file which returns the result.) the third drop down box elements are to be update based on the selection made in the second drop down box (selecting an element on the second drop down...
0
8233
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8170
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8675
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8619
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8334
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7158
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1784
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1482
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.