Based off a selection from an above drop-down on the same page?
Populate a second drop down based on a selection from another above it
Collapse
X
-
Originally posted by mimscBased off a selection from an above drop-down on the same page?
want and display the thing. What's the problem? Or are you talking Javascript?
kind regards,
JosComment
-
Originally posted by r035198xYes it's possible.
Are you talking about a Java application or an web application with HTML and Javascript?
here's what I got:
Code:<% Vector theStates = WeatherDAO.getWeatherStates(); %> label for="weatherStat">State:</label> <select name="weatherStat" id="States"> <% for (int i=0; i< theStates.size(); i++) { %> <OPTION VALUE=<%=theStates%>> <%=theStates.elementAt(i)%> </OPTION> <% } %> </select> <label for="weatherCity">City:</label> <select name="weatherCity" id="Cities"> <% Vector theCities = WeatherDAO.getWeatherCities(WeatherStat); %> <% for (int i=0; i< theCities.size(); i++) { %> <OPTION VALUE=<%=theCities%>> <%=theCities.elementAt(i)%> </OPTION> <% } %> </TD></TR> </center> <TR><TD> <br> <br> <center> </select></TD></TR> </TABLE>
Comment
-
Originally posted by mimscIt'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:
Code:<% Vector theStates = WeatherDAO.getWeatherStates(); %> label for="weatherStat">State:</label> <select name="weatherStat" id="States"> <% for (int i=0; i< theStates.size(); i++) { %> <OPTION VALUE=<%=theStates%>> <%=theStates.elementAt(i)%> </OPTION> <% } %> </select> <label for="weatherCity">City:</label> <select name="weatherCity" id="Cities"> <% Vector theCities = WeatherDAO.getWeatherCities(WeatherStat); %> <% for (int i=0; i< theCities.size(); i++) { %> <OPTION VALUE=<%=theCities%>> <%=theCities.elementAt(i)%> </OPTION> <% } %> </TD></TR> </center> <TR><TD> <br> <br> <center> </select></TD></TR> </TABLE>
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 forumComment
-
Originally posted by r035198x1.) 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...appreci ate itComment
-
Need help in passing a value
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:
[code=html]
<%
Vector theStates = WeatherDAO.getW eatherStates();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script language="JavaS cript"
type="text/JavaScript">
function GetCities(testV ar)
{
var weatherState = document.testFo rm.weatherStat. selectedIndex; <<----- I need to use this value to create another drop down menu on this same page
}
</script>
<body>
<TR bgColor="#fffff f"><TD COLSPAN="2">
<TABLE CELLPADDING="3" CELLSPACING="2" >
<TR><TD>
</FONT></CENTER><BR>
<BR>
<TABLE BORDER="0" CELLSPACING="5" CELLPADDING="5" WIDTH="100%">
<TR BGCOLOR="#C0C0C 0" ><TD COLSPAN="2" ALIGN="CENTER"> <FONT SIZE=+3><B> Weather Services</B></FONT>
</TD></TR>
</TABLE>
<HR SIZE="3" NOSHADE>
<font size=+1>Select the State and City for which you would like to receive weather information.</font><br>
<TR><TD>
<center>
<form name="testForm" >
<label for="weatherSta t">State:</label>
<select name="weatherSt at" onchange="testV ar = this.value">
<% for (int i=0; i< theStates.size( ); i++) { %>
<OPTION VALUE=<%=theSta tes%>> <%=theStates.el ementAt(i)%> </OPTION>
<%
}
%>
</select>
<label for="weatherCit y">City:</label>
<select name="weatherCi ty" id="Cities">
[/code]
Im lost...any help would be appreciatedComment
-
Originally posted by iam_clintnot sure what your asking can you try to explain alittle more
I need to grab the selected value from "weatherSta t" 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.getW eatherStates(th is is where the captured value needs to go)
Im new to javascriptComment
-
Originally posted by mimscI need to grab the selected value from "weatherSta t" 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.getW eatherStates(th is is where the captured value needs to go)Comment
-
Originally posted by acoderYou 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?Comment
Comment