469,344 Members | 5,413 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

Populate a second drop down based on a selection from another above it

14
Based off a selection from an above drop-down on the same page?
Sep 10 '07 #1
16 2253
r035198x
13,262 8TB
Based off a selection from an above drop-down on the same page?
Yes it's possible.
Are you talking about a Java application or an web application with HTML and Javascript?
Sep 10 '07 #2
JosAH
11,448 Expert 8TB
Based off a selection from an above drop-down on the same page?
Sure, why not? Instantiate a new PopupMenu and populate it with whatever you
want and display the thing. What's the problem? Or are you talking Javascript?

kind regards,

Jos
Sep 10 '07 #3
JosAH
11,448 Expert 8TB
r035198x is catching up: he beat me by that >.< much ;-)

kind regards,

Jos
Sep 10 '07 #4
mimsc
14
Yes it's possible.
Are you talking about a Java application or an web application with HTML and Javascript?
It's a web app with some html, unfortunately I'm new to javascript and I hear thats the way to go with this problem.

here's what I got:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3. Vector theStates = WeatherDAO.getWeatherStates();
  4. %>
  5.  
  6. label for="weatherStat">State:</label>
  7.  
  8. <select name="weatherStat" id="States">
  9. <% for (int i=0; i< theStates.size(); i++) {  %>
  10.  
  11. <OPTION VALUE=<%=theStates%>> <%=theStates.elementAt(i)%> </OPTION>
  12.  
  13. <% 
  14. }
  15. %>
  16. </select>        
  17.  
  18. <label for="weatherCity">City:</label>
  19.     <select name="weatherCity" id="Cities">
  20.  
  21.  
  22. <%
  23. Vector theCities = WeatherDAO.getWeatherCities(WeatherStat);
  24. %>    
  25.  
  26. <% for (int i=0; i< theCities.size(); i++) {  %>
  27.  
  28. <OPTION VALUE=<%=theCities%>> <%=theCities.elementAt(i)%> </OPTION>
  29.  
  30. <% 
  31. }
  32. %>
  33.  
  34.  
  35. </TD></TR>
  36. </center>
  37. <TR><TD> 
  38. <br>
  39. <br>
  40. <center>
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. </select></TD></TR>
  48. </TABLE>
  49.  
nothing populates in the second drop-down
Sep 10 '07 #5
r035198x
13,262 8TB
It's a web app with some html, unfortunately I'm new to javascript and I hear thats the way to go with this problem.

here's what I got:

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3. Vector theStates = WeatherDAO.getWeatherStates();
  4. %>
  5.  
  6. label for="weatherStat">State:</label>
  7.  
  8. <select name="weatherStat" id="States">
  9. <% for (int i=0; i< theStates.size(); i++) {  %>
  10.  
  11. <OPTION VALUE=<%=theStates%>> <%=theStates.elementAt(i)%> </OPTION>
  12.  
  13. <% 
  14. }
  15. %>
  16. </select>        
  17.  
  18. <label for="weatherCity">City:</label>
  19.     <select name="weatherCity" id="Cities">
  20.  
  21.  
  22. <%
  23. Vector theCities = WeatherDAO.getWeatherCities(WeatherStat);
  24. %>    
  25.  
  26. <% for (int i=0; i< theCities.size(); i++) {  %>
  27.  
  28. <OPTION VALUE=<%=theCities%>> <%=theCities.elementAt(i)%> </OPTION>
  29.  
  30. <% 
  31. }
  32. %>
  33.  
  34.  
  35. </TD></TR>
  36. </center>
  37. <TR><TD> 
  38. <br>
  39. <br>
  40. <center>
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47. </select></TD></TR>
  48. </TABLE>
  49.  
nothing populates in the second drop-down
1.) Vector is old. Use ArrayList
2.) If the cities are coming from a database as well then you probably may have to do it using Ajax or else you load all cities and states into arrays and then play around with those arrays. Either way it's a web problem so I'll move this to the Javascript forum.

P.S This problem appears so often that if you do a search on it you'll find a solution in the Javascript forum
Sep 10 '07 #6
mimsc
14
1.) Vector is old. Use ArrayList
2.) If the cities are coming from a database as well then you probably may have to do it using Ajax or else you load all cities and states into arrays and then play around with those arrays. Either way it's a web problem so I'll move this to the Javascript forum.

P.S This problem appears so often that if you do a search on it you'll find a solution in the Javascript forum

thanx for the input...appreciate it
Sep 10 '07 #7
acoder
16,027 Expert Mod 8TB
See if this link helps.
Sep 10 '07 #8
mimsc
14
See if this link helps.

hey thanx man, Im about to look at it right now!
Sep 10 '07 #9
mimsc
14
ok so I think I got the javascript syntax down...how can I access the saved parameter inside the script to be used in a query to populate a "city" drop-down menu below

example below:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Vector theStates = WeatherDAO.getWeatherStates();
  3. %>
  4.  
  5.  
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  9. <title>Insert title here</title>
  10. <script language="JavaScript" 
  11.    type="text/JavaScript">
  12. function GetCities(testVar)
  13.  {
  14.    var weatherState = document.testForm.weatherStat.selectedIndex;  <<----- I need to use this value to create another drop down menu on this same page
  15.  
  16.  
  17.  }
  18. </script>
  19.  
  20. <body>
  21.  
  22.  
  23.  
  24.  
  25. <TR bgColor="#ffffff"><TD COLSPAN="2">
  26. <TABLE CELLPADDING="3" CELLSPACING="2">
  27. <TR><TD>
  28.  
  29. </FONT></CENTER><BR>
  30. <BR>
  31. <TABLE BORDER="0" CELLSPACING="5" CELLPADDING="5" WIDTH="100%">
  32. <TR BGCOLOR="#C0C0C0" ><TD COLSPAN="2" ALIGN="CENTER"> <FONT SIZE=+3><B> Weather Services</B></FONT>
  33. </TD></TR>
  34. </TABLE>
  35. <HR SIZE="3" NOSHADE>
  36. <font size=+1>Select the State and City for which you would like to receive weather information.</font><br>
  37. <TR><TD> 
  38. <center>
  39.  
  40. <form name="testForm">
  41. <label for="weatherStat">State:</label>
  42.  
  43. <select name="weatherStat" onchange="testVar = this.value"> 
  44.  
  45. <% for (int i=0; i< theStates.size(); i++) {  %>
  46.  
  47. <OPTION VALUE=<%=theStates%>> <%=theStates.elementAt(i)%> </OPTION>
  48.  
  49. <% 
  50. }
  51. %>
  52. </select>
  53.  
  54. <label for="weatherCity">City:</label>
  55.     <select name="weatherCity" id="Cities">
  56.  
  57.  
  58.  


Im lost...any help would be appreciated
Sep 10 '07 #10
iam_clint
1,208 Expert 1GB
not sure what your asking can you try to explain alittle more
Sep 10 '07 #11
mimsc
14
not sure what your asking can you try to explain alittle more

I need to grab the selected value from "weatherStat" select box and use it in another dop down menu below called "weatherCity".....the only catch is the cites have to be populated by a query that's in:

Vector theStates = WeatherDAO.getWeatherStates(this is where the captured value needs to go)


Im new to javascript
Sep 10 '07 #12
acoder
16,027 Expert Mod 8TB
Merged your threads - they were on the same topic.

Also changed the thread title to describe the problem a little better.
Sep 11 '07 #13
acoder
16,027 Expert Mod 8TB
I need to grab the selected value from "weatherStat" select box and use it in another dop down menu below called "weatherCity".....the only catch is the cites have to be populated by a query that's in:

Vector theStates = WeatherDAO.getWeatherStates(this is where the captured value needs to go)
You have two choices. You can either use Ajax where you pass the selected value onto the server-side script which returns the response which you can parse to populate the second dropdown. The second option is to use arrays to store the option name/values ready for use as shown in the example link. You can generate the options as and when they are needed. Which method would you prefer?
Sep 11 '07 #14
mimsc
14
You have two choices. You can either use Ajax where you pass the selected value onto the server-side script which returns the response which you can parse to populate the second dropdown. The second option is to use arrays to store the option name/values ready for use as shown in the example link. You can generate the options as and when they are needed. Which method would you prefer?

the arrays sound too cumbersome, especially with cities for all 50 states....how does that AJAX work?
Sep 11 '07 #15
acoder
16,027 Expert Mod 8TB
the arrays sound too cumbersome, especially with cities for all 50 states....how does that AJAX work?
Check out the Ajax tutorial links in the Offsite Links thread. Also check out this example in the articles section.
Sep 11 '07 #16
mimsc
14
Check out the Ajax tutorial links in the Offsite Links thread. Also check out this example in the articles section.
thanx man.....good looking out
Sep 11 '07 #17

Post your reply

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

Similar topics

6 posts views Thread by Greg Scharlemann | last post: by
1 post views Thread by Greg Scharlemann | last post: by
1 post views Thread by ckerns | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.