Ok, I know on this BB that someone always seems to have an answer for something, and since there are alot of nerds that play this game (God love ya!) I need your help with a simple java script I'm trying to put on a website. Here's what I'm trying to do....
I want a menu (Menu1) to populate a second menu (Menu2) with content specific to the selection in menu one. Like subcategories of the main category selected. For example, when you select "CD reviews" in Menu1, then Menu2 will populate with "Local Music" & "National Acts". See? very very simple script. Keep in mind I am a Java n00b and I have tried to compare this script with others I have found and it looks like it should work.
I have posted my Head and Form scripts below. Menu1 works fine, but Menu2 just stays at "select one" and never populates. If someone could tell me what the hell I'm doing wrong it would be greatly appreciated. :)
<head>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
var reviewarray = new Array("('Subcategory','',true,true)",
"('Local Music')",
"('National Acts')");
var interviewarray = new Array("('Subcategory','',true,true)",
"('Musicians')",
"('Artists')",
"('Other')");
var showarray = new Array("('Subcategory','',true,true)",
"('Local Music')",
"('National Acts')");
var localarray = new Array("('Subcategory','',true,true)",
"('Local music news')",
"('Other')");
function populatesubcategory(inForm,selected) {
var selectedarray = eval(selected + "array");
while (selectedarray.length < inForm.subcategory.options.length) {
inForm.subcategory.options[(inForm.subcategory.options.length - 1)] = null;
}
for (var i=0; i < selectedarray.length; i++) {
eval("inForm.subcategory.options[i]=" + "new Option" + selectedarray[i]);
}
if (inForm.catgegory.options[0].value == '') {
inForm.category.options[0]= null;
if ( navigator.appName == 'Netscape') {
if (parseInt(navigator.appVersion) < 4) {
window.history.go(0);
}
else {
if (navigator.platform == 'Win32' || navigator.platform == 'Win16') {
window.history.go(0);
}
}
}
}
}
// End -->
</script>
</head>
<form name="newspost">
<SELECT NAME="category"
onChange="populateSubcategory(document.newspost,document.newspost.category.options[document.newspost.category.selectedIndex].value)">
<OPTION SELECTED VALUE="null">*select one*</option>
<OPTION VALUE="review">CD reviews</option>
<OPTION VALUE="interview">Interviews</option>
<OPTION VALUE="show">Show reviews</option>
<OPTION VALUE="local">Local Music</option>
</SELECT><br>
<select name="subcategory">
<option value=''>"select one"</option>
</select>
Calling all Java junkies (need some help)
-
- Sojourner
- Posts: 7
- Joined: Thu Jan 30, 2003 6:01 am
- Location: Birmingham, AL, USA
-
- Sojourner
- Posts: 262
- Joined: Wed Oct 31, 2001 6:01 am
- Location: Oakville, ON, CA
- Contact:
Return to “General Discussion Archive”
Who is online
Users browsing this forum: No registered users and 17 guests