Calling all Java junkies (need some help)

Archived discussion from Toril-2.
Werg
Sojourner
Posts: 180
Joined: Mon Apr 23, 2001 5:01 am
Location: da Swamp
Contact:

Calling all Java junkies (need some help)

Postby Werg » Thu Jul 01, 2004 12:45 pm

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>
Brogdagorripor
Sojourner
Posts: 7
Joined: Thu Jan 30, 2003 6:01 am
Location: Birmingham, AL, USA

Postby Brogdagorripor » Thu Jul 01, 2004 2:55 pm

First change the case on the function name from populatesubcategory to populateSubcategory.

Next, change the check within populateSubcategory from if (inForm.catgegory.options[0].value == '') to if (inForm.category.options[0].value == '')

That should take care of the problems you are seeing.
Werg
Sojourner
Posts: 180
Joined: Mon Apr 23, 2001 5:01 am
Location: da Swamp
Contact:

Postby Werg » Thu Jul 01, 2004 3:31 pm

Gaahh!!! It worked!! I didn't notice the little mispelling there...also didn't notice the "S"/"s" discrepency. You rock.. thank you much :)
Iaiken Toransier
Sojourner
Posts: 262
Joined: Wed Oct 31, 2001 6:01 am
Location: Oakville, ON, CA
Contact:

Postby Iaiken Toransier » Fri Jul 02, 2004 10:21 pm

Werg wrote:Gaahh!!! It worked!! I didn't notice the little mispelling there...also didn't notice the "S"/"s" discrepency. You rock.. thank you much :)


In my experience, it's almost always a syntax or null pointer error...

Once again, bad spelling pwns a coder.
Werg
Sojourner
Posts: 180
Joined: Mon Apr 23, 2001 5:01 am
Location: da Swamp
Contact:

Postby Werg » Fri Jul 02, 2004 10:27 pm

eh.. in this case it was also a n00b error. I figure one thing out, then I try to make it as hard on myself as I can. "Oh this is cool.. I wonder if I can do this and this and this and this to it too!!" *3 hours later* "Crap... now it doesn't work at all..."

Return to “General Discussion Archive”

Who is online

Users browsing this forum: No registered users and 17 guests