Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    459
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Populate dropdown with another dropdown, dynamically

    I have 2 drop down menu's and only want options in the second one, once the user has selected their options from the first one. For the second list I also want the data to be pulled from a table in my database... Each row has a column called FirstName and a column called Reference. Reference is either Blue, Red, Green, Pink. If they select Pink then I want all the FirstName's that have Pink in their Reference column to populate into the second dropdown... Anyone know of a simple way to do this? I have seen some very complex examples...

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Three options the way I see it--

    If you don't mind using Javascript then this option will provide the smoothest ride for your user. The idea is to build the Javascript code on the fly using PHP. You build a Javascript array and populate it with the data from your table. Then as the user makes selections from the first selectbox, use Javascript to fill the second selectbox from the Javascript array you built using PHP.

    If you want to use Ajax that will also be a smooth ride for your user.

    The least smooth would be to submit the form every time an option is selected in the first selectbox, taking control back over to PHP to gather the data for the second selectbox and re-create the HTML page, now with the options in the second selectbox.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •