...

View Full Version : Form Drop down



cap_0ne
08-30-2004, 11:44 PM
I want to create a drop down where when u select 1 option, in the drop down next to its selections become available. like for a car. when u pick the maker lest say honda... in the drop doen next to it, the honda models become available. like here for instance: http://c.qckjmp.com/az/ch.php?f=426&i=600. I already have the selection done in a js file but i'm getting error messages on my script. any suggestions.

Basscyst
08-31-2004, 01:40 AM
Suggestion 1: Use the search function of this forum.

Suggestion 2: Post your code should your search not find you an answer.

Basscyst

jamescover
08-31-2004, 05:23 AM
see subsequent post :thumbsup:

And thanks for visiting.



-james

hemebond
08-31-2004, 07:25 AM
You'll need php to emulate this functionality.Not true. Go to http://deviantart.com

cap_0ne
08-31-2004, 05:04 PM
what am i looking for on deviant art.

cap_0ne
08-31-2004, 05:28 PM
here is my code. I got it from another source but it keeps tellin me that the the reg file is null and void. attached is the html and the js file.

JPM
08-31-2004, 06:02 PM
Dont know whats wrong there ^, but this seems to be working:


<html>
<head>

<script type="text/javascript">
var honda = new Array(3);
honda[0] = "honda1";
honda[1] = "honda2";
honda[2] = "honda3";

var bmw = new Array(3);
bmw[0] = "BMW 1";
bmw[1] = "BMW 2";
bmw[2] = "BMW 3";

function add1(form)
{
var n = form.options[form.selectedIndex].value;
if(n=="honda") addCars(honda);
else if(n=="bmw") addCars(bmw);
}

function addCars(brand)
{
var newOpt;
for(i=0;i<brand.length;i++)
{
newOpt = new Option(brand[i],brand + i)
document.form1.select2.options[i] = newOpt;
}
}

</script>
</head>

<body>

<form name="form1">
<select name="select1" onchange="add1(this)">
<option value="bmw">BMW</option>
<option value="honda">Honda</option>
</select>
<select name="select2">
</select>
</form>

</body>
</html>

cap_0ne
08-31-2004, 06:10 PM
the code works.... but u see how many car makes and models there are? how do i link that to the js file i have?

jamescover
08-31-2004, 11:32 PM
Not true. Go to http://deviantart.com

Yes, I should have said, I think that using php/db would be a better choice for something like this.



automake=new Array(39);
automodel=new Array(39);
automakecount=39;
automake[0]='Make';
automodel[0]= new Array('Model');
automake[1]='Acura';
automodel[1]= new Array('CL','Integra','Legend','MDX 4x4','RL','RSX','SLX 4x4','TL','Vigor');
automake[2]='Audi';
automodel[2]= new Array('100','100 AWD','5000','80','90','90 AWD','A4','A4 Quattro','A6','A6 Quattro','A8','A8 Quattro','Cabriolet','Quattro','S4 Quattro','S6 Quattro','TT','TT Quattro');
automake[3]='BMW';
automodel[3]= new Array('318','323','325','328','330','330 AWD','525','528','530','535','540','735','740','X5 AWD','Z3');
automake[4]='Buick';
automodel[4]= new Array('Century','Electra','Grand National','LeSabre','Park Avenue','Raineer','Raineer 4x4','Reatta','Regal','Rendezvous','Rendezvous AWD','Riviera','Roadmaster','Skylark');
automake[5]='Cadillac';
automodel[5]= new Array('Brougham','Catera','DeVille','Eldorado','Escalade','Escalade AWD','Fleetwood','Northstar','Seville');
automake[6]='Chevrolet';
automodel[6]= new Array('1500','1500 4x4','1500 4x4 Diesel','1500 Diesel','2500','2500 4x4','2500 4x4 Diesel','2500 Diesel','3500','3500 4x4','3500 4x4 Diesel','3500 Diesel','APV','Astro','Astro AWD','Avalanche','Avalanche 4X4','Beretta','Blazer','Blazer 4x4','Blazer 4x4 Diesel','Camaro','Camaro V8','Caprice','Cavalier','Celebrity','Corsica','Corvette','Express','G10','G20','G20 Diesel','G30','Impala','Impala SS','Iroc/Z28','Lumina','Lumina APV','Malibu','Metro','Monte Carlo','Monte Carlo SS','Nova','Prizm','S10','S10 4x4','S10 Blazer','S10 Blazer 4x4','Spectrum','SSR','Suburban','Suburban 4x4','Suburban 4x4 Turbo Diesel','Suburban Turbo Diesel','Tahoe','Tahoe 4x4','Tahoe 4x4 Turbo Diesel','Tahoe Turbo Diesel','Tracker','Tracker 4x4','Trail Blazer','Trailblazer','Trailblazer 4x4','Venture','Venture 4x4');
automake[7]='Chrysler';
automodel[7]= new Array('300M','Cirrus','Concord LHS','Concorde','Fifth Ave','Grand Voyager','Imperial','Intrepid','Intrepid 24V','LeBaron','LHS','Minivan','Minivan AWD','New Yorker','PT Cruiser','Sebring','Town & Country','Town & Country AWD','Voyager');
automake[8]='Daihatsu';
automodel[8]= new Array('Charade','Rocky 4x4');
automake[9]='Dodge';
automodel[9]= new Array('150','150 4x4','1500','1500 4x4','250','250 4x4','250 4x4 Diesel','250 Diesel','2500','2500 4x4','2500 4x4 Diesel','2500 Diesel','350','350 4x4','350 4x4 Diesel','350 Diesel','3500','3500 4x4','3500 4x4 Diesel','3500 Diesel','Avenger','Caravan','Caravan AWD','Colt','Colt 4x4','Dakota','Dakota 4x4','Daytona','Diplomat','Duranfo 4x4','Durango','Durango 4x4','Dynasty','Grand Caravan','Intrepid','Intrepid 24V','Monaco','Neon','Omni','Raider','Raider 4x4','Shadow','Spirit','Stratus');
automake[10]='Eagle';
automodel[10]= new Array('Premier','Summit','Summit AWD','Talon','Talon AWD','Vision');
automake[11]='Ford';
automodel[11]= new Array('150','250','350','Aerostar','Aerostar 4x4','Aspire','Bronco','Bronco 4x4','Club Wagon','Club Wagon Diesel','Contour','Crown Victoria','Econoline','Econoline Diesel','Escape','Escape 4x4','Escort','Excursion','Excursion 4x4','Excursion 4x4 Diesel','Excursion Diesel','Expedition','Expedition 4x4','Explorer','Explorer 4x4','F150','F150 4x4','F150 4x4 Diesel','F150 Diesel','F250','F250 4x4','F250 4x4 Diesel','F250 Diesel','F350','F350 4x4','F350 4x4 Diesel','F350 Diesel','Festiva','Focus','Mustang','Mustang GT','Probe','Ranger','Ranger 4x4','Taurus','Taurus SHO','Tempo','Thunderbird','Windstar','ZX2');
automake[12]='Geo';
automodel[12]= new Array('Metro','Prizm','Spectrum','Storm','Tracker','Tracker 4x4');
automake[13]='GMC';
automodel[13]= new Array('1500','1500 4x4','1500 4x4 Diesel','1500 Diesel','2500','2500 4x4','2500 4x4 Diesel','2500 Diesel','3500','3500 4x4','3500 4x4 Diesel','3500 Diesel','Envoy','Envoy 4x4','Jimmy','Jimmy 4x4','S15','S15 4x4','Safari','Safari AWD','Saffari','Sonoma','Sonoma 4x4','Suburban','Suburban 4x4','Suburban 4x4 Diesel','Suburban Diesel','Yukon','Yukon 4x4','Yukon 4x4 Diesel','Yukon Diesel');
automake[14]='Honda';
automodel[14]= new Array('Accord','Civic','CRV','CRV 4x4','CRX','Del Sol','Odyssey','Passport','Passport 4x4','Pilot','Prelude','S2000');
automake[15]='Hyundai';
automodel[15]= new Array('Accent','Elantra','Excel','Santa Fe','Santa Fe 4x4','Scoupe','Sonata','Tiburon','XG300');
automake[16]='Infiniti';
automodel[16]= new Array('G20','I30','I35','J30','M30','Q45','QX4','QX4 4x4');
automake[17]='Isuzu';
automodel[17]= new Array('Amigo','Amigo 4x4','Axiom','Axiom 4x4','Hombre','Hombre 4x4','Imark','Impulse','Impulse AWD Turbo','Oasis','Pickup','Pickup 4x4','Rodeo','Rodeo 4x4','Stylus','Trooper','Trooper 4x4','VehiCross 4x4');
automake[18]='Jaguar';
automodel[18]= new Array('S-Type','XJ6','XJ8','XJS','XK8');
automake[19]='Jeep';
automodel[19]= new Array('Cherokee','Cherokee 4x4','CJ7','CJ7 4x4','Grand Cherokee','Grand Cherokee 4x4','Grand Wagoneer','Grand Wagoneer 4x4','Liberty','Liberty 4x4','Pickup','Pickup 4x4','Wrangler','Wrangler 4x4');
automake[20]='Kia';
automodel[20]= new Array('Optima','Rio','Sephia','Spectra','Sportage','Sportage 4x4');
automake[21]='Lexus';
automodel[21]= new Array('ES 250','ES 300','ES 400','GS 300','GS 400','GS 430','IS 300','LS 400','LS 430','LX 450 4x4','LX 470 4x4','RX 300','RX 300 AWD','SC 300','SC 400');
automake[22]='Lincoln';
automodel[22]= new Array('Aviator','Aviator 4x4','Blackwood','Continental','LS','Mark VII','Mark VIII','Navigator','Navigator 4x4','Town Car');
automake[23]='Mazda';
automodel[23]= new Array('323','626','929','B2200','B2200 4X4','B2300','B2300 4x4','B2500','B2500 4x4','B2600','B2600 4X4','B3000','B3000 4x4','B4000','B4000 4x4','Mazda 6','Miata','Millenia','MPV','MPV 4x4','MX3','MX6','Navajo','Navajo 4x4','Pickup','Pickup 4x4','Protege','RX7','Tribute','Tribute 4x4');
automake[24]='Mercedes';
automodel[24]= new Array('190','260','300','300 4x4','300D Diesel','300SD Diesel','380SL','400','420','500','C220','C230','C240','C280','C320','C36','C43','CL500','CLK320','C LK430','E300 Diesel','E320','E320 AWD','E420','E430','E430 AWD','E500','E55','ML320 4x4','ML430','S320','S350 Turbo Diesel','S420','S430','S500','SL320','SL500','SLK230');
automake[25]='Mercury';
automodel[25]= new Array('Capri','Cougar','Grand Marquis','Mountaineer','Mountaineer 4x4','Mountaineer AWD','Mystique','Sable','Topaz','Tracer','Villager');
automake[26]='Mitsubishi';
automodel[26]= new Array('Diamante','Eclipse','Eclipse AWD','Expo','Expo AWD','Galant','Galant AWD','Mirage','Montero','Montero 4x4','Montero Sport','Montero Sport 4x4','Pickup','Pickup 4x4','Precis','Starion');
automake[27]='Nissan';
automodel[27]= new Array('200SX','240SX','300ZX','Altima','Frontier','Frontier 4x4','Maxima','Murano','NX','Pathfinder','Pathfinder 4x4','Pickup','Pickup 4x4','Quest','Sentra','Stanza','Xterra','Xterra 4x4');
automake[28]='Oldsmobile';
automodel[28]= new Array('88','98','Achieva','Alero','Aurora','Bravada','Bravada AWD','Calais','Ciera','Custom Cruiser','Cutlass','Cutlass Cruiser','Delta 88','Intrigue','LSS','Regency','Royale','Silhouette','Toronado');
automake[29]='Plymouth';
automodel[29]= new Array('Acclaim','Breeze','Colt','Colt AWD','Grand Voyager','Grand Voyager AWD','Horizon','Laser','Laser AWD','Laser Turbo','Neon','Reliant','Sundance','Voyager','Voyager AWD');
automake[30]='Pontiac';
automodel[30]= new Array('6000','Aztek','Aztek AWD','Bonneville','Fiero','Firebird','Formula','Grand Am','Grand Prix','LeMans','Montana','Montana AWD','Sunbird','Sunfire','Trans Am','Trans Sport','Vibe','Vibe AWD');
automake[31]='Porsche';
automodel[31]= new Array('911','928','968','Boxster');
automake[32]='Saab';
automodel[32]= new Array('9-3','9-5','900','900 Turbo','9000','Aero','Viggen');
automake[33]='Saturn';
automodel[33]= new Array('L100','L200','L300','LS','LW','SC','SL','SW','vue','VUE AWD');
automake[34]='Subaru';
automodel[34]= new Array('Forester AWD','Impreza','Impreza AWD','Justy','Legacy','Legacy AWD','Loyale','Loyale AWD','Outback AWD','SVX','SVX AWD');
automake[35]='Suzuki';
automodel[35]= new Array('Aerio','Esteem','Grand Vitara','Grand Vitara 4x4','Samurai','Samurai 4x4','Sidekick','Sidekick 4x4','Swift','Vitara','Vitara 4x4','X90','X90 4x4','XL7','XL7 4x4');
automake[36]='Toyota';
automodel[36]= new Array('4Runner','4Runner 4x4','Avalon','Camry','Camry AWD','Celica','Celica AWD','Corolla','Corolla AWD','Cressida','Echo','Highlander','Highlander 4x4','Land Cruiser AWD','Matrix','Matrix AWD','MR2','MR2 Turbo','Paseo','Pickup','Pickup 4x4','Previa','Previa AWD','RAV4','RAV4 4x4','Sequoia','Sequoia 4x4','Sienna','Solara','T100','T100 4x4','Tacoma','Tacoma 4x4','Tercel','Tundra','Tundra 4x4');
automake[37]='Volkswagen';
automodel[37]= new Array('Cabrio','Cabriolet','Corrado','Fox','Golf','Golf Diesel','GTI','Jetta','Jetta Diesel','Minivan','New Beetle','New Beetle Diesel','New Beetle Turbo','Passat','Passat AWD','Passat Diesel','Scirocco');
automake[38]='Volvo';
automodel[38]= new Array('240','740','760','780','850','940','960','C70','S40','S60','S60 AWD','S70','S70 AWD','S80','S90','V40','V70','V70 AWD','V90','XC90');


-james

JPM
09-01-2004, 05:24 PM
This should do it:


<html>
<head>

<script type="text/javascript" src="arrays.js" />
</script>

<script type="text/javascript">

function add1(form)
{
var n = form.options[form.selectedIndex].value;
var b = rA(n);
addCars(b)
}

function addCars(brand)
{
var newOpt;
for(i=0;i<brand.length;i++)
{
newOpt = new Option(brand[i],brand + i)
document.form1.select2.options[i] = newOpt;
}
}

</script>
</head>

<body>

<form name="form1">
<select name="select1" onchange="add1(this)">
<option value="bmw">BMW</option>
<option value="honda">Honda</option>
</select>
<select name="select2">
</select>
</form>

</body>
</html>

and the arrays.js file with the arrays:



var honda = new Array(3);
honda[0] = "honda1";
honda[1] = "honda2";
honda[2] = "honda3";

var bmw = new Array(3);
bmw[0] = "BMW 1";
bmw[1] = "BMW 2";
bmw[2] = "BMW 3";

function rA(n)
{

if(n=="honda") return honda
else if(n=="bmw") return bmw

}

JPM
09-01-2004, 05:27 PM
A switch statement would probarly be better in the rA function in the .js file when you have a lot of arrays....



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum