hw09_08countries and cities.html 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. <head>
  2. <h1>countries and cities</h1>
  3. </head>
  4. <body>
  5. <select id='country'> </select><br>
  6. <select id='city'></select>
  7. <script>
  8. fetch('https://raw.githubusercontent.com/russ666/all-countries-and-cities-json/master/countries.min.json').then(res => res.json())
  9. .then(data => {
  10. for (countryName in data) {
  11. let option = document.createElement("option");
  12. option.innerText = countryName;
  13. country.append(option);
  14. }
  15. const onChangeCountry = () => {
  16. city.innerText = "";
  17. let test = data[country.value];
  18. for (cityName of data[country.value]) {
  19. let option = document.createElement("option");
  20. option.innerText = cityName;
  21. city.append(option);
  22. }
  23. }
  24. country.onchange = onChangeCountry;
  25. onChangeCountry();
  26. });
  27. </script>
  28. </body>+