...

View Full Version : Dynamic dropdowns [solved]



M.W.S.
08-01-2008, 02:53 PM
Hello, I need to make a dynamic 2 level dropdown for auto trading site. It will receive model lists from MySQL. And it will be like on cars.com (makes and models).
I have this piece of JS:

<script type="text/javascript">

var makelist=document.classic.make
var modellist=document.classic.model

var model=new Array()
model[0]=""
model[1]=["A4|A4", "A6|A6", "A8|A8", "TT|TT", "Q7|Q7"]
model[2]=["M3|M3", "M5|M5", "M6|M6", "325|325"]
model[3]=["Enzo|Enzo", "F30|F30", "F50|F50"]

function updatemodel(selectedcitygroup){
modellist.options.length=0
if (selectedcitygroup>0){
for (i=0; i<model[selectedcitygroup].length; i++)
modellist.options[modellist.options.length]=new Option(model[selectedcitygroup][i].split("|")[0], model[selectedcitygroup][i].split("|")[1])
}
}

</script>

So basically, I will need to update this:

model[0]=""
model[1]=["A4|A4", "A6|A6", "A8|A8", "TT|TT", "Q7|Q7"]
model[2]=["M3|M3", "M5|M5", "M6|M6", "325|325"]
model[3]=["Enzo|Enzo", "F30|F30", "F50|F50"]


So, any ideas? :rolleyes:

ptmuldoon
08-01-2008, 06:41 PM
Well, your in the php forum, and asking about javascript, but........

I was just asking a similar question myself. See my post here. I found a nice php script that may help you out.

http://www.codingforums.com/showthread.php?t=145548

Len Whistler
08-01-2008, 06:51 PM
This is a PHP code I use to give you an idea where to start.


<select>
<?php
$sql = mysql_query("SELECT id, project FROM project_supplies ORDER BY id ASC");
while($item = mysql_fetch_array($sql)){
echo "<option value=\"$item[1].php#$item[0]\">$item[0]</option>\n";
}
?>
</select>


-----------------

M.W.S.
08-01-2008, 07:27 PM
Thanks for reply.
But, I think you don't get what I wanted.
You see, I want to make a menu, sort of this:
http://img111.imageshack.us/img111/5584/aaawi1.jpg (http://imageshack.us)
http://img111.imageshack.us/img111/5584/aaawi1.5f2cd1fd56.jpg (http://g.imageshack.us/g.php?h=111&i=aaawi1.jpg)

(see cars.com)

I could do this manually, but It will be veeeery tiring. So I wanted to just add a menu item and subitem from DB.

ptmuldoon
08-01-2008, 07:30 PM
What Len Whistler showed you will do the trick. Just google around for dynamic selects.

ohgod
08-01-2008, 07:31 PM
look into multiselects

http://www.infimum.dk/HTML/multiselect.html

just an example

Len Whistler
08-02-2008, 12:08 AM
Thanks for reply.
But, I think you don't get what I wanted.
You see, I want to make a menu, sort of this:
http://img111.imageshack.us/img111/5584/aaawi1.jpg (http://imageshack.us)
http://img111.imageshack.us/img111/5584/aaawi1.5f2cd1fd56.jpg (http://g.imageshack.us/g.php?h=111&i=aaawi1.jpg)

(see cars.com)

I could do this manually, but It will be veeeery tiring. So I wanted to just add a menu item and subitem from DB.

You would have to add a while loop within a while loop of the PHP code I posted to populate the Javascript code from the MySQL database.

OR

Maybe an Ajax solution might be better. I don't know anything about Ajax but I do believe that Ajax is for this sort of thing.





-----------

M.W.S.
08-02-2008, 05:46 PM
Thanks for replies :)

Finally, I did it using this:
http://www.yxscripts.com/cs/chainedselects.html and PHP file manipulation.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum