I am looking to extract the key from a JSON file and then populate another select input with the corresponding values using JavaScript.
Below is the structure of my JSON file:
"city": {
"Afghanistan": [
"Herat",
"Kabul",
"Kandahar",
"Molah",
"Rana",
"Shar",
"Sharif",
"Wazir Akbar Khan"
],
"Albania": [
"Elbasan",
"Petran",
"Pogradec",
"Shkoder",
"Tirana",
"Ura Vajgurore"
],
The goal is to display only the country names in one select input, and when a user selects a country, all cities belonging to that country should be dynamically loaded into the other input field.
Here is the current HTML code snippet I am working with:
<div class="form-group">
<label for="Country">Country</label>
<select class="custom-select" id="Country">
<option selected>Choose...</option>
</select>
</div>
<div class="form-group">
<label for="ville">Ville</label>
<select class="custom-select" id="ville">
</select>
</div>