•
•
•
•
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 391,912 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,662 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: 2422 | Replies: 0
![]() |
•
•
Join Date: Oct 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
Here's how to dynamically fill a dropdown box depending on the selection of another dropdown box. I looked all over the web, and in this forum, finally I found someone who knew what they were talking about and actually had code that worked.
:lol:
:lol:
<%@LANGUAGE="Javascript"%>
<html>
<head>
<title>Load Dropdown</title>
<script language="JavaScript">
<!--
var tennisplayers = new Array("Safin","Andre Agassi","Pete Sampras","Anna Kournik","Martina Hingis");
var cricketplayers = new Array("Sachin Tendulkar","Steve Waugh","Brian Lara","Sir Bradman");
function set_player(){
var select_sport= document.form1.sport;
var select_player= document.form1.player;
var selected_sport= select_sport.options[select_sport.selectedIndex].value;
select_player.options.length=0;
if (selected_sport == "tennis"){
for(var i=0; i < tennisplayers.length; i++)
select_player.options[select_player.options.length] = new Option(tennisplayers[i],tennisplayers[i]);
}
if (selected_sport == "cricket"){
for(var i=0; i < cricketplayers.length; i++)
select_player.options[select_player.options.length] = new Option(cricketplayers[i],cricketplayers[i]);
}
}
-->
</script>
</head>
<body>
<form name="form1"><div align="center">Select Sport
<select name="sport" onChange="set_player();">
<option value="" selected="selected">Select Sport</option>
<option value="tennis">Tennis</option>
<option value="cricket">Cricket</option>
</select> Select Player
<select name="player">
<option value="" selected="selected"></option>
</select>
</form>
</body>
</html>
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
- Filling 2nd dropdown by choice in first (JavaScript / DHTML / AJAX)
- Filling values of a dropdown (JavaScript / DHTML / AJAX)
- Dropdown menu (JavaScript / DHTML / AJAX)
- DropDown List (VB.NET)
- Feeding a value in a dropdown list to another dropdown list (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: Dani Webs Code?
- Next Thread: CSS & JS Menu Problem on IE


Linear Mode