Skip to content
Advertisement

PHP Country Option list adding “select” tag with checking String value?

I want to select a target country in html.

And this code should return for example “Turkey” from my db.

JavaScript

I have a country list, and I use it here in settings_myinfo.php :

JavaScript

countries_optionlist.php :

JavaScript

I want to add selected tag to target country like this:

JavaScript

I did some research on Google and StackOverflow but I couldn’t find any solution. Could you provide me with a suggestion on how to achieve this?

Advertisement

Answer

In each option, you can check if the session variable matches that country and add the selected attribute.

JavaScript

You can simplify this by putting all the country names in an array. Then you can loop like this:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement