Jump to content

[SOLVED] whyyyy :( ... A little situation here guys


npsari

Recommended Posts

I have this Double Combo Box

 

<form name="doublecombo">
<p><select name="Main" size="12" onChange="redirect(this.options.selectedIndex)">
<option>Select...</option>
<option>For Sale</option>
<option>Wanted</option>
<option>Jobs</option>
<option>Events</option>
<option>Services</option>
<option>Free!</option>
<option>Other</option>
</select>
<select name="Category" size="12">
<option value="http://javascriptkit.com">Select...</option>
</select>
</p>

<script>
<!--

/*
Double Combo Script Credit
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free JavaScripts here!
*/

var groups=document.doublecombo.Main.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option("Select from Main","No Category selected!")

group[1][0]=new Option("Electrical devices","For Sale - Electrical devices")
group[1][1]=new Option("Computers","For Sale - Computers")
group[1][2]=new Option("Clothes","For Sale - Clothes")
group[1][3]=new Option("Furniture","For Sale - Furniture")
group[1][4]=new Option("Pets","For Sale - Pets")
group[1][5]=new Option("Books & Magazines","For Sale - Books & Magazines")
group[1][7]=new Option("Jewelery","For Sale - Jewelery")
group[1][8]=new Option("Toys & Games","For Sale - Toys & Games")
group[1][9]=new Option("Other","For Sale - Other")

group[2][0]=new Option("Electrical devices","Wated - Electrical devices")
group[2][1]=new Option("Computers","Wanted - Computers")
group[2][2]=new Option("Clothes","Wanted - Clothes")
group[2][3]=new Option("Furniture","For Sale - Furniture")
group[2][4]=new Option("Pets","For Sale - Pets")
group[2][5]=new Option("Books & Magazines","For Sale - Books & Magazines")
group[2][7]=new Option("Jewelery","For Sale - Jewelery")
group[2][8]=new Option("Toys & Games","For Sale - Toys & Games")
group[2][9]=new Option("Other","For Sale - Other")

group[3][0]=new Option("General Part-time","Jobs- General Part-time")
group[3][1]=new Option("General Full-time","Jobs- General Full-time")
group[3][2]=new Option("Engineering","Jobs - Engineering")
group[3][3]=new Option("Business","Jobs - Business")
group[3][4]=new Option("Voluntary work","Jobs - Voluntary work")

group[4][0]=new Option("Shows","Events - Shows")
group[4][1]=new Option("Meetings","Events - Meetings")
group[4][2]=new Option("Special Offers","Events - Special offers")
group[4][3]=new Option("Fun & Outdoors","Events - Fun & Outddors")
group[4][4]=new Option("Night life","Events - Night life")

group[5][0]=new Option("Removals","Services - Removals")
group[5][1]=new Option("Electrical","Services - Electrical")
group[5][2]=new Option("Mechanical","Services - Mechanical")
group[5][3]=new Option("Building","Services - Building")

group[6][0]=new Option("Stuff","Free - Stuff")
group[6][1]=new Option("Services","Free - Services")
group[6][2]=new Option("Pets","Free - Pets")
group[6][3]=new Option("Other!","Free - Other!")

group[7][0]=new Option("Advertising","Other - Advertising")
group[7][1]=new Option("Websites","Other - Websites")

var temp=document.doublecombo.Category

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}
//-->
</script>
</form>

 

it works fine, but only 5 options show on the second combo box

 

why???

Link to comment
Share on other sites

I got it :)

 

Look at your group1 and group2 arrays...you skipped over #6 in both arrays so it blew up the for loop.

 

So it should look like:

<form name="doublecombo">
<p><select name="Main" size="12" onChange="redirect(this.options.selectedIndex)">
<option>Select...</option>
<option>For Sale</option>
<option>Wanted</option>
<option>Jobs</option>
<option>Events</option>
<option>Services</option>
<option>Free!</option>
<option>Other</option>
</select>
<select name="Category" size="12">
<option value="http://javascriptkit.com">Select...</option>
</select>
</p>

<script>
<!--

/*
Double Combo Script Credit
By JavaScript Kit (www.javascriptkit.com)
Over 200+ free JavaScripts here!
*/

var groups=document.doublecombo.Main.options.length
var group=new Array(groups)
for (i=0; i<groups; i++)
group[i]=new Array()

group[0][0]=new Option("Select from Main","No Category selected!")

group[1][0]=new Option("Electrical devices","For Sale - Electrical devices")
group[1][1]=new Option("Computers","For Sale - Computers")
group[1][2]=new Option("Clothes","For Sale - Clothes")
group[1][3]=new Option("Furniture","For Sale - Furniture")
group[1][4]=new Option("Pets","For Sale - Pets")
group[1][5]=new Option("Books & Magazines","For Sale - Books & Magazines")
group[1][6]=new Option("Jewelery","For Sale - Jewelery")
group[1][7]=new Option("Toys & Games","For Sale - Toys & Games")
group[1][8]=new Option("Other","For Sale - Other")

group[2][0]=new Option("Electrical devices","Wated - Electrical devices")
group[2][1]=new Option("Computers","Wanted - Computers")
group[2][2]=new Option("Clothes","Wanted - Clothes")
group[2][3]=new Option("Furniture","For Sale - Furniture")
group[2][4]=new Option("Pets","For Sale - Pets")
group[2][5]=new Option("Books & Magazines","For Sale - Books & Magazines")
group[2][6]=new Option("Jewelery","For Sale - Jewelery")
group[2][7]=new Option("Toys & Games","For Sale - Toys & Games")
group[2][8]=new Option("Other","For Sale - Other")

group[3][0]=new Option("General Part-time","Jobs- General Part-time")
group[3][1]=new Option("General Full-time","Jobs- General Full-time")
group[3][2]=new Option("Engineering","Jobs - Engineering")
group[3][3]=new Option("Business","Jobs - Business")
group[3][4]=new Option("Voluntary work","Jobs - Voluntary work")

group[4][0]=new Option("Shows","Events - Shows")
group[4][1]=new Option("Meetings","Events - Meetings")
group[4][2]=new Option("Special Offers","Events - Special offers")
group[4][3]=new Option("Fun & Outdoors","Events - Fun & Outddors")
group[4][4]=new Option("Night life","Events - Night life")

group[5][0]=new Option("Removals","Services - Removals")
group[5][1]=new Option("Electrical","Services - Electrical")
group[5][2]=new Option("Mechanical","Services - Mechanical")
group[5][3]=new Option("Building","Services - Building")

group[6][0]=new Option("Stuff","Free - Stuff")
group[6][1]=new Option("Services","Free - Services")
group[6][2]=new Option("Pets","Free - Pets")
group[6][3]=new Option("Other!","Free - Other!")

group[7][0]=new Option("Advertising","Other - Advertising")
group[7][1]=new Option("Websites","Other - Websites")

var temp=document.doublecombo.Category

function redirect(x){
for (m=temp.options.length-1;m>0;m--)
temp.options[m]=null
for (i=0;i<group[x].length;i++){
	temp.options[i]=new Option(group[x][i].text,group[x][i].value)
}
temp.options[0].selected=true
}

function go(){
location=temp.options[temp.selectedIndex].value
}
//-->
</script>
</form>

Link to comment
Share on other sites

Notice in yours group[1] goes from group[1][0] to group[1][9] you are MISSING group[1][6] this is also the case for group[2]

 

In mine it goes from group[1][0] to group[1][8] because I added changed 7 to 6, 8 to 7, and 9 to 8. same for group[2]

 

Make sense?

Link to comment
Share on other sites

BTW, that why you should be using push() instead... like:

 

group[0].push( new Option("Select from Main","No Category selected!") );

group[1].push( new Option("Electrical devices","For Sale - Electrical devices") );
group[1].push( new Option("Computers","For Sale - Computers") );

 

And so on...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.