I am just beginning to learn JavaScript and I am struggling to figure out how to allow the user to change the city name in this request. Currently, it works when I manually input the city name in the code (e.g., askWeather.open("GET", "url.../london")), but how can I enable the user to input their desired city?
Any help would be greatly appreciated.
askWeather.onreadystatechange = function () {
if (this.readyState === XMLHttpRequest.DONE && this.status == 200) {
var response = JSON.parse(this.responseText);
let resp = document.getElementById('result');
let ask = document.getElementById('btn');
ask.addEventListener('click', function () {
resp.innerHTML = response.current_condition.condition;
});
}
};
askWeather.open("GET", "https://www.prevision-meteo.ch/services/json/lille");
askWeather.send();