•
•
•
•
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 401,945 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,359 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: 1742 | Replies: 0
![]() |
•
•
Join Date: Oct 2006
Posts: 7
Reputation:
Rep Power: 0
Solved Threads: 0
I'm trying to fill the values of a dropdown SelectMenu depending on the selection in another menu, but this code is not working. What am I doing wrong?
[<%@LANGUAGE="Javascript"%>
<html>
<head>
<title>Load Dropdown</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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 (select_sport == "tennis"){
for(var i=0; i<tennisplayers.length; i++)
select_player.options[select_player.options.length] = new Option(tennisplayer[i]);
}
if (selected_sport == "cricket"){
for(var i=0; i<cricketplayers.length; i++)
select_player.options[select_player.options.length] = new option(cricketplayer[i]);
}
}
-->
</script>
</head>
<body>
<form name="form1" method=">
<table align="center" cellpadding="0" cellspacing="0" border="2" bordercolor="#000066">
<tr valign="baseline" bgcolor="#66FFFF">
<td nowrap align="left" width="182" valign="top">
<div align="left"><b><font size="2" face="Arial, Helvetica, sans-serif">SPORT</font></b></div></td>
<td width="219" nowrap="false"><font size="2" face="Times New Roman, Times, serif">
<select name="sport" onChange="set_player()" size="1">
<option value="tennis">-------
<option value="tennis">Tennis
<option value="cricket">Cricket
</select>
</tr>
<tr valign="baseline" bgcolor="#66FFFF">
<td nowrap align="right" width="182" valign="top">
<div align="left"><b><font size="2" face="Arial, Helvetica, sans-serif">PLAYERS</font></b></div></td>
<td width="219" nowrap="false"><font size="2" face="Times New Roman, Times, serif">
<select name="player">
<option>-------
</select>
</tr>
</form>
</body>
</html>]
[<%@LANGUAGE="Javascript"%>
<html>
<head>
<title>Load Dropdown</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<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 (select_sport == "tennis"){
for(var i=0; i<tennisplayers.length; i++)
select_player.options[select_player.options.length] = new Option(tennisplayer[i]);
}
if (selected_sport == "cricket"){
for(var i=0; i<cricketplayers.length; i++)
select_player.options[select_player.options.length] = new option(cricketplayer[i]);
}
}
-->
</script>
</head>
<body>
<form name="form1" method=">
<table align="center" cellpadding="0" cellspacing="0" border="2" bordercolor="#000066">
<tr valign="baseline" bgcolor="#66FFFF">
<td nowrap align="left" width="182" valign="top">
<div align="left"><b><font size="2" face="Arial, Helvetica, sans-serif">SPORT</font></b></div></td>
<td width="219" nowrap="false"><font size="2" face="Times New Roman, Times, serif">
<select name="sport" onChange="set_player()" size="1">
<option value="tennis">-------
<option value="tennis">Tennis
<option value="cricket">Cricket
</select>
</tr>
<tr valign="baseline" bgcolor="#66FFFF">
<td nowrap align="right" width="182" valign="top">
<div align="left"><b><font size="2" face="Arial, Helvetica, sans-serif">PLAYERS</font></b></div></td>
<td width="219" nowrap="false"><font size="2" face="Times New Roman, Times, serif">
<select name="player">
<option>-------
</select>
</tr>
</form>
</body>
</html>]
![]() |
•
•
•
•
•
•
•
•
DaniWeb JavaScript / DHTML / AJAX Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
- php drop down menu to search multiple sql tables (PHP)
- Convert database values into Dropdown List (PHP)
- Filling 2nd dropdown by choice in first (JavaScript / DHTML / AJAX)
- JSP: How to Extract values from dropdown (JSP)
- Feeding a value in a dropdown list to another dropdown list (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: JavaScript problem in FF
- Next Thread: java to javascript


Linear Mode