Dependant drop-down menus

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
Wardy7
Forum Commoner
Posts: 38
Joined: Wed Aug 24, 2005 4:45 am
Location: UK

Dependant drop-down menus

Post by Wardy7 »

I have a MYSQL database that contains car makes in one column and all the different models from than manufacturer in the columns next to it.
e.g.
Ford - Fiesta - Focus - Galaxy - GT - Mustang - Puma - etc.

Anyway, what I want to create is a drop down menu of the Manufacturers and when a manufacturer is selected another dropdown menu automatically gets populated with all the models of car for that manufacturer.

Is anyone able to help? I have searched a bit on the internet but can't find anything that is of any help! :(

Cheers
Wardy

***edit***Just thought this may have been better in the Database section?!
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Post by Chalks »

I think you'll probably want to take a gander at this ajax tutorial... I just read it myself :). I don't think you'll be able to create the second menu without at least a small amount of time to query the database and whatnot, but... it shouldn't take too long.

Alternatively, you could pre-create all the possible menus in your page, and set them all to invisible, then onmouseover set visible menu X, and onmouseout hide menu X. That would probably be simpler unless you have a huge number of possible menus. You can easily do that using html, css and javascript. The problem with doing that is if your end user had javascript disabled, they probably wouldn't be able to see the menus. There are workarounds for that however. The easiest being whenever you click on a link, go to a page that includes the submenu already visible.
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Javascript and Dynamic Select Boxes is probably a more meaningful tutorial on these boards if I understand you requirements correctly. If this doesn't suit what you need the phrase you may want to use when searching is "Dynamic Select Boxes" or "Chained Selects".
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Moved to client side.

This could be done with no Javascript, but it would require a post to the server. Otherwise, it would require javascript (this exact question has been asked here before and answered here before so you might want to search a little bit around. Yes, the exact question. Yes, car makers, then car models.).

Be forewarned that users that don't have javascript enabled will still need a means by which to use your dropdowns.
Post Reply