npsari Posted April 12, 2007 Share Posted April 12, 2007 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??? Quote Link to comment https://forums.phpfreaks.com/topic/46746-solved-whyyyy-a-little-situation-here-guys/ Share on other sites More sharing options...
cmgmyr Posted April 12, 2007 Share Posted April 12, 2007 did you try putting the JS in the head section of the html? Quote Link to comment https://forums.phpfreaks.com/topic/46746-solved-whyyyy-a-little-situation-here-guys/#findComment-227821 Share on other sites More sharing options...
npsari Posted April 12, 2007 Author Share Posted April 12, 2007 Yep, I just did it still stops at 5 Quote Link to comment https://forums.phpfreaks.com/topic/46746-solved-whyyyy-a-little-situation-here-guys/#findComment-227843 Share on other sites More sharing options...
cmgmyr Posted April 12, 2007 Share Posted April 12, 2007 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> Quote Link to comment https://forums.phpfreaks.com/topic/46746-solved-whyyyy-a-little-situation-here-guys/#findComment-227854 Share on other sites More sharing options...
npsari Posted April 12, 2007 Author Share Posted April 12, 2007 Hey, it works now its great how you spotted the problem Can you tell me which bit did you change I know php a little but i dont know nothing in Javascript thanks pal Quote Link to comment https://forums.phpfreaks.com/topic/46746-solved-whyyyy-a-little-situation-here-guys/#findComment-227868 Share on other sites More sharing options...
cmgmyr Posted April 12, 2007 Share Posted April 12, 2007 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? Quote Link to comment https://forums.phpfreaks.com/topic/46746-solved-whyyyy-a-little-situation-here-guys/#findComment-227873 Share on other sites More sharing options...
npsari Posted April 12, 2007 Author Share Posted April 12, 2007 Ohh I cant beleive such a little thing can cause a mistake but yet again, thats fair Thanks dude, and thanks for your eagle eyes Quote Link to comment https://forums.phpfreaks.com/topic/46746-solved-whyyyy-a-little-situation-here-guys/#findComment-227883 Share on other sites More sharing options...
cmgmyr Posted April 12, 2007 Share Posted April 12, 2007 not a problem...it had me a little confused at first too. Thats whats good/bad about programming...very unforgiving Glad I could help you out. Quote Link to comment https://forums.phpfreaks.com/topic/46746-solved-whyyyy-a-little-situation-here-guys/#findComment-227927 Share on other sites More sharing options...
fenway Posted April 12, 2007 Share Posted April 12, 2007 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... Quote Link to comment https://forums.phpfreaks.com/topic/46746-solved-whyyyy-a-little-situation-here-guys/#findComment-227980 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.