+ 2
Could someone tell me how to create a dynamic dropdown menu using php.?
eg. user selects a state from state tag then dynamically cities must be fetched from the database as options in select tag.
4 Réponses
+ 5
Without Ajax:
if you want to use the data from a database, you could fetch it all at the beginning, create all the possible select with php and only show the right one with js, upon user selection of the country.
Definitely not an optimal solution.
Another approach would require reloading the page upon user country selection, to retreive the secondary menu data and create the corresponding select. Depending on your project it may not be ideal from a UX point of view.
+ 4
Check out this Ajax example
https://www.w3schools.com/php/php_ajax_database.asp
instead of creating a table, as in the example, populate and show the secondary select.
+ 2
No. Because the client get the executed php code from the server. without reloading the page you have to use client side programming language.
+ 1
there is no alternative to ajax?