I am trying to create a form with a drop down menu where once an item is selected the values in another drop down menu are changed based on the value of the first menu. Not all of the menu items have further sub-categories so the value is null for now.
I am getting the error:
'team' is undefined
Please note I was trying to use the source code from here:
http://javascript.internet.com/forms/auto-drop-down.htmlPlease can somebody find the error in my script! Thanks in advance!
Here is the script:
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
team = new Array(
null,
null,
null,
null,
null,
null,
null,
new Array(
new Array("Old School Rap", 1),
new Array("Rap Metal", 2),
new Array("Gangsta Rap", 3),
new Array("Southern Rap", 4),
new Array("Dirty South", 5)
),
null,
null,
null,
null,
null,
null,
);
function fillSelectFromArray(select
Ctrl, itemArray, goodPrompt, badPrompt, defaultItem) {
var i, j;
var prompt;
// empty existing items
for (i = selectCtrl.options.length;
i >= 0; i--) {
selectCtrl.options[i] = null;
}
prompt = (itemArray != null) ? goodPrompt : badPrompt;
if (prompt == null) {
j = 0;
}
else {
selectCtrl.options[0] = new Option(prompt);
j = 1;
}
if (itemArray != null) {
// add new items
for (i = 0; i < itemArray.length; i++) {
selectCtrl.options[j] = new Option(itemArray[i][0]);
if (itemArray[i][1] != null) {
selectCtrl.options[j].valu
e = itemArray[i][1];
}
j++;
}
// select first item (prompt) for sub list
selectCtrl.options[0].sele
cted = true;
}
}
// End -->
</script>
and the form:
<form method="POST" name="main" action="">
<SELECT NAME="Make" onChange="fillSelectFromAr
ray(this.f
orm.Team, ((this.selectedIndex == -1) ? null : team[this.selectedIndex-1]
));">
<option value="-1">-</option>
<option value="1">Alternative</opt
ion>
<option value="2">Blues</option>
<option value="3">Classical</optio
n>
<option value="4">Country</option>
<option value="5">Jazz</option>
<option value="6">Metal</option>
<option value="7">New Age</option>
<option value="8">Rap</option>
<option value="9">R&B</option>
<option value="10">Rock</option>
<option value="11">Electronica</op
tion>
<option value="12">Pop</option>
<option value="13">Soul</option>
<option value="14">Christian</opti
on>
</select>
<SELECT NAME="Team" SIZE="5">
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
<OPTION> </OPTION>
</SELECT>
</form>
Start Free Trial