Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Javascript coding help: Drop down menu not displaying names?

Hello,

I can choose a team but once I choose a team I should be able to choose a list of players on the right drop down box but does not display them here is the code:

<!DOCTYPE>

<html>

<head>

<title>Team Rosters</title>

<script type="text/javascript">

/* <![cdata{ */

// 5 arrays with 5 players each + array [0] as default

cat = new Array()

cat [0] = new Array(1)

cat [0][0] = " "

cat [1] = new Array()

cat [1] [0] = "Bryant, Kobe"

cat [1] [1] = "Blake, Steve"

cat [1] [2] = "Boateng, Eric"

cat [1] [3] = "Farmar, Jordan"

cat [1] [4] = "Gasol, Paul"

cat [2] = new Array()

cat [2] [0] = "Barnes, Matt"

cat [2] [1] = "Amundson, Lou"

cat [2] [2] = "Bullock, Reggie"

cat [2] [3] = "Griffin, Blake"

cat [2] [4] = "Paul, Chris"

cat [3] = new Array()

cat [3] [0] = "Boozer, Carlos"

cat [3] [1] = "Butler, Jimmy"

cat [3] [2] = "Gibson, Taj"

cat [3] [3] = "Snell, Tony"

cat [3] [4] = "White, DJ"

cat [4] = new Array()

cat [4] [0] = "Allen, Ray"

cat [4] [1] = "Anderson, Chris"

cat [4] [2] = "James, Lebron"

cat [4] [3] = "Lewis, Rashard"

cat [4] [4] = "Griffin, Eric"

cat [5] = new Array()

cat [5] [0] = "Baynes, Aron"

cat [5] [1] = "Ayres, Jeff"

cat [5] [2] = "Duncan, Tim"

cat [5] [3] = "Parker, Tony"

cat [5] [4] = "Bonner, Matt"

function ListRoster()

{

var num=document.form1.team.selectedIndex

var boxlength = 0

document.form1.roster.selectedIndex = 0

for ( ctr=0;ctr<roster[num].length;ctr++)

{

boxlength++;

document.form1.roster.options[ctr] = new Option(roster[num] [ctr], roster[num][ctr]);

}

document.form1.roster.length = boxlength;

document.form1.roster.options.length = boxlength;

document.form1.roster.focus() ;

}

/* }}> */

</script>

</head>

<body>

<form id="form1" name="form1" method="post" action="">

<label for="team">Team Name</label>

<select name="team" id="team" onchange="JavaScript:ListRoster()">

<option selected="selected" value="">Choose Team</option>

<option value="1">Lakers</option>

<option value="2">Clippers</option>

<option value="3">Bulls</option>

<option value="4">Heat</option>

<option value="5">Spurs</option>

</select>

<label for="roster">Team Rosters</label>

<select name="roster" size="1" id="roster">

<option value="Choose Roster">Choose Roster</option>

</select>

</form>

</body>

</html>

1 Answer

Relevance
  • ?
    Lv 7
    8 years ago
    Favorite Answer

    Here are the changes I suggest.

    Line 59

    for ( ctr=0;ctr<cat[num].length;ctr++)

    Line 62

    document.form1.roster.options[ctr] = new Option(cat[num] [ctr], cat[num][ctr]);

    - Dominic

Still have questions? Get your answers by asking now.