•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 373,930 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,255 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 696 | Replies: 1
![]() |
•
•
Join Date: Aug 2007
Posts: 40
Reputation:
Rep Power: 1
Solved Threads: 0
Hi I want to populate my second drop-down menu based off of the value selected on my first drop down. Is there a function or a way of doin g this...
P.S my code is in a JSP:
P.S my code is in a JSP:
java Syntax (Toggle Plain Text)
<% Vector theStates = WeatherDAO.getWeatherStates(); %> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <TR bgColor="#ffffff"><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="#C0C0C0" ><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> <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> > </TD></TR> </center> <TR><TD> <br> <br> <center> <label for="weatherCity">City:</label> <select name="weatherCity" id="Cities"> <% Vector theCities = WeatherDAO.getWeatherCities();// <<this is wher I need to pass the selected value %> <OPTION VALUE= </OPTION> <% } %> </select></TD></TR>
•
•
Join Date: Dec 2007
Posts: 6
Reputation:
Rep Power: 0
Solved Threads: 1
What you need to do the following:
1. Add the onchange event attribute to the 1st select tag
2. Create a javascript function called addNewValue for example.
Note: Place in the <head></head> tags
Ok, whats happening here, is that when an item is selected in your first select States, the onchange attribute event is fired, which in turn calls our addNewValue() javascript function. By the way, the $('Cities') notation is the same as document.getElementById.....
In the above example, for simplicity reasons
, we are just adding the selected value to the first element of the Cities select box.
1. Add the onchange event attribute to the 1st select tag
<select name="weatherStat" id="States" onchange="addNewValue();">
2. Create a javascript function called addNewValue for example.
Note: Place in the <head></head> tags
function addNewValue() {
$('Cities').options[0] = new Option($('States').value, 0);
}
Ok, whats happening here, is that when an item is selected in your first select States, the onchange attribute event is fired, which in turn calls our addNewValue() javascript function. By the way, the $('Cities') notation is the same as document.getElementById.....
In the above example, for simplicity reasons
, we are just adding the selected value to the first element of the Cities select box. Last edited by tommybobby : Dec 3rd, 2007 at 12:51 pm.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Javascript links not working (Web Browsers)
- JavaScript's window.opener (JavaScript / DHTML / AJAX)
- recommendations for JavaScript learning resources? (JavaScript / DHTML / AJAX)
- Javascript/HTML problem!!! (JavaScript / DHTML / AJAX)
- Javascript Useful? (IT Careers and Business)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: HELP needed on javascript menus PLEASE...
- Next Thread: pop window question


Linear Mode