I am facing an issue with populating a dropdown list depending on the value selected from another dropdown. My goal is to accomplish this using vanilla JavaScript instead of jQuery. I need the second dropdown to be populated with sample data provided below:
Sample Data:
[{"1":"ABA NORTH"},{"2":"ABA SOUTH"},{"3":"AROCHUKWU"},{"4":"BENDE"},{"5":"IKWUANO"},{"6":"ISIALA NGWA NORTH"},{"7":"ISIALA NGWA SOUTH"},{"8":"ISUIKWUATO"},{"9":"OBINGWA"},{"10":"OHAFIA"},{"11":"OSISIOMA"},{"12":"UGWUNAGBO"},{"13":"UKWA EAST"},{"14":"UKWA WEST"},{"15":"UMUAHIA NORTH"},{"16":"UMUAHIA SOUTH"},{"17":"UMU - NNEOCHI"}]
HTML:
<select name="states" id="profileapplicationform-lga_id">
<option value="">Select one</option>
</select>
JavaScript:
<script type="text/javascript">
window.onload = function(e){
var select = document.getElementById("profileapplicationform-state_origin_id");
select.addEventListener('change', function(){
// AJAX request here
/* Implementation goes here */
});
}
</script>
After selecting a value in the main dropdown, although I can see the sample data in the response under the network tab, the dependent dropdown remains empty. Any help would be much appreciated.