Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linked Drop Down Menu

Status
Not open for further replies.

jsteiner87

Programmer
Oct 9, 2003
76
US
I am creating a site where I need to link drop down menus. What I have is one mySQL table of Companies and a mySQL table of Facilities, and a Company can have more that one Facility. I want 2 drop down menus the first being the Company. When the Company is selected then the second drop down menu would only show the Facilities of the Company selected in the first drop down menu. I have seen this done before but I don't know if I am able to do this with PHP or if I need to use something else.
 
If you want the second dropdown to be populated automatically, you will need to use client-side JavaScript as well as PHP.

PHP creates a page which, given no input, populates the first dropdown. (I generally don't even show the second dropdown at this point). The dropdown is in a form which submits back to the PHP script that originally created the page. The dropdown has JavaScript included in its "onchange" attribute which automatically submits the form when the selection in the dropdown is changed.

When the original PHP script gets a value from the first dropdown it recreates the page, populating and selecting the value in the first dropdown and populating the second dropdown with data from the database selected on the value from the first dropdown.

I also include submit buttons on these pages. Some users have JavaScript turned off in their browsers as a security measure.


Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top