php dropdown menu population

后端 未结 4 1545
广开言路
广开言路 2021-01-01 08:31

I\'m trying to write a php script that will populate a second drop down menu based on the selection of the a primary drop down menu. I would like to use jquery to do all the

4条回答
  •  生来不讨喜
    2021-01-01 09:08

    There are quite a few examples of how to do this on the web, a good one here from Remy Sharp on his blog (full example here)

    Basically what you're doing is calling a PHP page on your server with the value of your first drop-down whenever it is changed. For example, if your first drop down is a list of states in the US, your second drop-down may show cities in the chosen state. When the first drop down is selected, it's onChange event fires off a request to a PHP page on your server, passing the state name (example.com/city_lookup.php?state=NY)

    The JQuery then receives the response from the city_lookup script (JSON encoded is probably the best way to go here), then cycles through it and writes the values to your second drop-down menu.

提交回复
热议问题