cha0sriderx Posted December 14, 2007 Share Posted December 14, 2007 im trying to use a loop to load a list of items into a few combo boxes but it keeps stopping at 2 instead of doing all 5. php that lists the cars and towns: <? $cars = array( "1"=>"Acura Integra GS-R" , "2"=>"Mitsubishi Lancer Evolution VIII" , "3"=>"Scion tC" , "4"=>"Acura Rsx Type-S" , "5"=>"Infiniti G35 Coupe" , "6"=>"Ford Mustang GT" , "7"=>"Honda Integra Type-R" , "8"=>"Honda S2000" , "9"=>"Chevrolet Corvette" , "10"=>"Ford GT" , "11"=>"Dodge Viper"); $towns = array( "1"=>"Toreno" , "2"=>"Newburge" , "3"=>"Creek side" , "4"=>"Vista" , "5"=>"Stock"); ?> javascript part: <script type="text/javascript"> cars =new Array() cars[4] =new Object() cars[4][1] =[{text:"None", town:"1"}]; cars[4][2] =[{text:"OEM Engine Mounts", town:"2"}]; cars[4][3] =[{text:"OEM Shocks", town:"2"}]; function parts() { town = document.setups.town.value; car = document.setups.car.value; i=0; z=1; x=0; if (car != 0 && town != 0 && town != "5") { alert('aaa'); for (z=1;z<=3;z++) { var part = document.getElementById(z); part.options.length = 0; db = cars[car][z]; if (db[0].text != "None") { for (i=0;i<=db.length;i++) { x = i + 1; if (db[i].town <= town) { part.options[x] = new Option(db[i].text, x); } } } } } if (town == "5") { for (p=1;p<=44;p++) { part = document.getElementById(p); part.options.length = 0; } } } </script> the form: <form name="setups"> <table class="form" cellpadding="2" cellspacing="0"> <tr> <td> </td> <td> <select name="town" onchange="parts()"> <option value="0" selected>Select A Town</option> <? for($i=1;$i<=count($towns);$i++) { echo "<option value=\"$i\">$towns[$i]</option>\r\n"; } ?> </select> <select name="car" onchange="parts()"> <option value="0" selected>Select A Car</option> <? for($i=1;$i<=count($cars);$i++) { echo "<option value=\"$i\">$cars[$i]</option>\r\n"; } ?> </select> </td> </tr> <tr> <td style="border-bottom: 1px solid #778;"> </td> <td style="border-bottom: 1px solid #778;"><b>Chassis & Suspension</b></td> </tr> <tr> <td align="right">FWD Traction System:</td> <td> <select name="1" id="1"> <option value="">x</option> </select> </td> </tr> <tr> <td align="right">Motor Mounts:</td> <td> <select name="2" id="2"> </select> </td> </tr> <tr> <td align="right">Springs & Shocks:</td> <td> <select name="3" id="3"> </select> </td> </tr> </table> </form> Link to comment https://forums.phpfreaks.com/topic/81636-changing-combo-boxes/ Share on other sites More sharing options...
emehrkay Posted December 14, 2007 Share Posted December 14, 2007 I really dont understand what you are trying to do, but this piece cars[4][1] =[{text:"None", town:"1"}]; creates another subarray with that object in it. so it looks like this cars[4][1][0] ={text:"None", town:"1"}; is that what you are going for? Link to comment https://forums.phpfreaks.com/topic/81636-changing-combo-boxes/#findComment-415036 Share on other sites More sharing options...
cha0sriderx Posted December 19, 2007 Author Share Posted December 19, 2007 yeah i want it to do it like that but when i have more than 1 part for that car i have what is below. after i find a fix for the reason it stops after 2 ill finish up all the other cars(11 total cars) and all the parts, the form is made for a setups page for a racing game i play online. cars[4][2] =[{text:"OEM Engine Mounts", town:"2"}, {text:"Part 2", town:"3"}]; Link to comment https://forums.phpfreaks.com/topic/81636-changing-combo-boxes/#findComment-418135 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.