I have three dropdowns:
- Country
- State
- City
When I select a value in the Country dropdown, it should show the States of the selected country. When I select a value in the State dropdown, it should show the Cities of the sele开发者_JAVA百科cted state.
All data is available in a XML file. I would like to populate the child dropdowns using Ajax and PHP. How can I achieve this?
You will essentially need a PHP script that handles the AJAX requests that populate the dropdowns. This script will accept parameters for Country and State and return the respective States and Cities respectively by parsing the appropriate XML file.
You will need to send an AJAX request at the onchange
method of the dropdowns. The PHP script can return the results as a JSON object which your JS framework can access to modify the values of the dropdowns.
You should be able to find code that will do this by Googling. If you have any trouble with getting it to work, ask here!
精彩评论