Good day Webflow Community!
I currently need help with a form block that includes something similar to a country & city type of field. I have gotten the code for the country from a separate forum query:
<script>
/* #### 1/2. select menu add countries #### */
function addCountries(whereto) {
var countriesfile = "United States of America, Afghanistan, Albania, Algeria, Andorra, Angola, Antigua & Deps, Argentina, Armenia, Australia, Austria, Azerbaijan, Bahamas, Bahrain, Bangladesh, Barbados, Belarus, Belgium, Belize, Benin, Bhutan, Bolivia, Bosnia Herzegovina, Botswana, Brazil, Brunei, Bulgaria, Burkina, Burma, Burundi, Cambodia, Cameroon, Canada, Cape Verde, Central African Rep, Chad, Chile, People's Republic of China, Republic of China, Colombia, Comoros, Democratic Republic of the Congo, Republic of the Congo, Costa Rica, Croatia, Cuba, Cyprus, Czech Republic, Danzig, Denmark, Djibouti, Dominica, Dominican Republic, East Timor, Ecuador, Egypt, El Salvador, Equatorial Guinea, Eritrea, Estonia, Ethiopia, Fiji, Finland, France, Gabon, Gaza Strip, The Gambia, Georgia, Germany, Ghana, Greece, Grenada, Guatemala, Guinea, Guinea-Bissau, Guyana, Haiti, Holy Roman Empire, Honduras, Hungary, Iceland, India, Indonesia, Iran, Iraq, Republic of Ireland, Israel, Italy, Ivory Coast, Jamaica, Japan, Jonathanland, Jordan, Kazakhstan, Kenya, Kiribati, North Korea, South Korea, Kosovo, Kuwait, Kyrgyzstan, Laos, Latvia, Lebanon, Lesotho, Liberia, Libya, Liechtenstein, Lithuania, Luxembourg, Macedonia, Madagascar, Malawi, Malaysia, Maldives, Mali, Malta, Marshall Islands, Mauritania, Mauritius, Mexico, Micronesia, Moldova, Monaco, Mongolia, Montenegro, Morocco, Mount Athos, Mozambique, Namibia, Nauru, Nepal, Newfoundland, Netherlands, New Zealand, Nicaragua, Niger, Nigeria, Norway, Oman, Ottoman Empire, Pakistan, Palau, Panama, Papua New Guinea, Paraguay, Peru, Philippines, Poland, Portugal, Prussia, Qatar, Romania, Rome, Russian Federation, Rwanda, St Kitts & Nevis, St Lucia, Saint Vincent & the, Grenadines, Samoa, San Marino, Sao Tome & Principe, Saudi Arabia, Senegal, Serbia, Seychelles, Sierra Leone, Singapore, Slovakia, Slovenia, Solomon Islands, Somalia, South Africa, Spain, Sri Lanka, Sudan, Suriname, Swaziland, Sweden, Switzerland, Syria, Tajikistan, Tanzania, Thailand, Togo, Tonga, Trinidad & Tobago, Tunisia, Turkey, Turkmenistan, Tuvalu, Uganda, Ukraine, United Arab Emirates, United Kingdom, Uruguay, Uzbekistan, Vanuatu, Vatican City, Venezuela, Vietnam, Yemen, Zambia, Zimbabwe";
var countries = countriesfile.split(", ");
for(var c = 0; c<countries.length; c++) {
$(whereto).append('<option value="' + countries[c] + '">' + countries[c] + '</option>');
}
}
Webflow.push(function() {
addCountries('#country');
});
/* #### 2/2. select menu add cities #### */
function addCities(whereto) {
var Citiesfile = "city1, city2, city3, city4, city5, city6";
var cities = Citiesfile.split(", ");
for(var c = 0; c<cities.length; c++) {
$(whereto).append('<option value="' + cities[c] + '">' + cities[c] + '</option>');
}
}
Webflow.push(function() {
addCities('#city');
});
</script>
But I wanted the cities to be dependent on what they pick for the Country, and not just list everything there. Is there a way to push a function that if I choose Country A for the first field, I only get the states/regions of Country A in the 2nd field?
Here is my site Read-Only:
https://preview.webflow.com/preview/livetrue?utm_medium=preview_link&utm_source=designer&utm_content=livetrue&preview=bae3f57e44f14fffce044c5c6864c7cf&pageId=643509755afac22d73142a8b&workflow=preview
The fields with IDs for the codes are the ones on the last part of the form