1234567891011121314151617181920212223242526272829303132 |
- <head>
- <h1>countries and cities</h1>
- </head>
- <body>
- <select id='country'> </select><br>
- <select id='city'></select>
- <script>
- fetch('https://raw.githubusercontent.com/russ666/all-countries-and-cities-json/master/countries.min.json').then(res => res.json())
- .then(data => {
- for (countryName in data) {
- let option = document.createElement("option");
- option.innerText = countryName;
- country.append(option);
- }
- const onChangeCountry = () => {
- city.innerText = "";
- let test = data[country.value];
- for (cityName of data[country.value]) {
- let option = document.createElement("option");
- option.innerText = cityName;
- city.append(option);
- }
- }
- country.onchange = onChangeCountry;
- onChangeCountry();
- });
-
- </script>
- </body>+
|