Populating A Drop Down Menu with Selection of a Previous Drop Down Menu


I am attempting to populate an HTML drop down menu based on the selection from a previous drop down menu and access to MySQL Database fields. I would like to populate three drop downs in total based on the data contained in the MySQL database. I already have built and have access to my database.


I would use javascript, but the make and model fields in the database are populated with several thousand entries. Is there a more effective/efficient way to populate these fields? If so, I would be very much open to recommendations or HTML/PHP scripting examples.

Welcome to the SP forums.
You might want to take a look at AJAX. Do a google search for ‘AJAX drop down’ or something like that and you should fine loads of tutorials and examples.

How often does this data change? Usually for data that isn’t mission critical, I use a scheduled task or a cronjob to write out the information to a flat file that I can just use a <?php include(‘path to file’); ?> on so the HTML is already built and can be easily included into your document. Then I schedule the task or cronjob to run nightly, weekly, whatever makes sense.

Is it that time of year again? You might want to look at what last year’s students did when they asked us to do their homework for them too. Search the forum a bit.

Thank you for the recommendation and welcoming–most of what I’ve found already is AJAX oriented–I’ll give that a shot. The Make, Model and Year values update per annum, but I do have other variables that will update as quickly as every five minutes. Sorry, StarLion, but I wish I was still in school. I’m a few years beyond that now and am just getting into server-side scripting.

If you are going to attempt a server-side only solution, you probably only need 2 webpages.

1 Pick year and make. (“2000” and “Ford”)

2 Show models (available matching models)

… then possibly link on to another page showing just that model?

I think we’d need to know what fields you have in each table, I’m especially interested to hear what you have in your “year” table …

Hi Peakbagger, welcome to the forums,

In school or out, we could all stand to learn a few things :wink:

If I understand you correctly, you have an initial form containing “common to all” selects, that when once chosen will lead to specific “not common to all” choices.

You are correct in wanting to get this to work server-side, javascript and AJAX can embellish the user’s experience, but you want things to work for everyone, including those without javascript.

So maybe something like this:

Initial page populates the select with the “common” values taken from the database.
Form sends input values to server.
Server finds applicable “specific” values and sends back a second form using those values.
Form sends those input values to the server.
Server sends back the final page.

You may be interested in using the QuickForm2 package as it would save you from a lot of work.

This package provides methods to create, validate and render HTML forms.


  • Supports all form elements defined by HTML standard, provides several
    custom elements
  • Server-side and client-side validation, several common rules provided
  • Multipage forms (tabbed forms and wizards)
  • Pluggable elements, rules, renderers and renderer plugins

Major advantages over PHP4 version:

  • Most of the package’s functionality is covered by unit tests
  • DOM-like API for building the form structure, new streamlined API for
    elements’ values handling
  • Default rendering without tables (inspired by
  • Renderer plugins for elements with complex rendering needs
  • Ability to chain validation rules with ‘and’ and ‘or’
  • Client-side validation can run “live” on changing the form fields,
    validation errors are displayed near the fields instead of in alert()