Autoload Car Make / Car Model Drop Down

Status
Not open for further replies.

HairyHun

Masturbating Bandit
Oct 11, 2007
576
2
0
Hi,

I'm trying to make a drop down for Make and Model, where the Model would load the appropriate choices depending on the Make.

Cars.com has something like that, on the first page.

I googled it to see if something like that is available freely, no luck there. I was trying to make sense of their code. (cars.com) Not much luck there.

I could write it out a list make/models, but how to make it dynamic?
Anyone has some suggestions about this or could help me out?

Thanks
HH
 


You want to do an AJAX call for the make in the select tag's onchange event attribute and fill the model select tag with the appropriate models.
 
You can utilize the code from this example:

Chained select boxes

The example uses a static secondary list but you can easily replace that with a query for the "models" from the database.
 
After Taking apart the Cars dot com page, I found an JS file that has all the models by make. But I was not able to understand the code that run it.

I will try that link! Thanks

HH
 
I made the chained box model operational. Now i have to fill the content.

Anyone can help me make a script for that?

THanks
HH
 
case "Acura":
echo "obj.options[obj.options.length] = new Option('A4','A4');\n";
echo "obj.options[obj.options.length] = new Option('A6','A6');\n";
echo "obj.options[obj.options.length] = new Option('A7','A7');\n";
echo "obj.options[obj.options.length] = new Option('TT','TT');\n";
echo "obj.options[obj.options.length] = new Option('Other','Other');\n";

break;


This is how the file that contains the models and makes is structured. I want to be able to fill it up without having to type it all in

HH
 
Code:
var Acura = ['A4','A6','A7','TT'];
for ( x=0; x < Acura.length; x++ ) {
  echo "obj.options[obj.options.length]=new Option('"+Acura[x]+"','"+Acura[x]+"');\n"; 

}
like that?
 
even:
Code:
<?php
$data="select model from cars where make='Acura'";
while ( list( $mod ) = mysql_fetch_row( $data ) ) {
  echo "obj.options[obj.options.length]=new Option('$mod','$mod');\n"
}
?>
 
even:
Code:
<?php
$data="select model from cars where make='Acura'";
while ( list( $mod ) = mysql_fetch_row( $data ) ) {
  echo "obj.options[obj.options.length]=new Option('$mod','$mod');\n"
}
?>


I guess I could replace the Acura by a variable and run a "for each"
Then now I just need a good source data.

i was able to get out of cars.com an text file, looks like an array. Hmmm...
 
Status
Not open for further replies.