I'm trying to call a JavaScript function (apiCall) using an event listener binded to a drop-down list listening for a change.
I want the function to re-run when a different menu item is selected from the drop-down list, but when I run this code, the error occurs on the event listener saying that 'apiCall' is not defined, even though it clearly is right above.
Any suggestions?
Thanks in advance.
// API CALL
var request = new XMLHttpRequest()
request.open('GET', base + forecast + key + city, true)
request.onload = function apiCall() {
var data = JSON.parse(this.response)
console.log(data)
string = JSON.stringify(data, null, 4);
app.innerHTML = string;
}
document.getElementById("locationList").addEventListener("change", apiCall)
//send request
request.send()