+ 1

How to display country, state and city in html select input?

I want to display all countries on my first select input. Once they select country will display state based on the selected country. Once they select State will display the cities based on the selected state. How to achieve this using javascript and jQuery

1st Jan 2021, 5:23 AM
ANBARASAN R
ANBARASAN R - avatar
7 ответов
+ 4
var species = { "Pisces" : [ "Whale", "Shark", "Salmon" ], "Aves" : [ "Eagle", "Dove", "Cockatoo" ], "Reptiles" : [ "Snake", "Iguana", "Komodo" ], "Amphibians" : [ "Salamander", "Frog", "Alligator" ], "Mammals" : [ "Horse", "Cat", "Dog"] }; You mentioned the options here. Instead of mention here can we get list of countries, states and cities in api or json?
1st Jan 2021, 7:13 AM
ANBARASAN R
ANBARASAN R - avatar
+ 2
This code isn't about countries, states or city, but the idea comes close to your plan. https://code.sololearn.com/Wsm58eJD3rmZ/?ref=app
1st Jan 2021, 6:52 AM
Ipang
+ 2
Thank you Ipang You have added options using static value. How to get all the countries list dynamically?
1st Jan 2021, 7:04 AM
ANBARASAN R
ANBARASAN R - avatar
+ 2
I haven't tried playing with APIs, but if the returned data was in JSON format then I think it's possible, if we know how the data was structured.
1st Jan 2021, 7:15 AM
Ipang
+ 2
Thanks for your advice.
1st Jan 2021, 7:23 AM
ANBARASAN R
ANBARASAN R - avatar
+ 2
You mean Maps on your website I know how to add live maps location in html
1st Jan 2021, 9:53 AM
Rohit Singh
Rohit Singh - avatar
+ 1
ANBARASAN R Sorry, I didn't get what you mean. Dynamically meaning?
1st Jan 2021, 7:11 AM
Ipang