Hello All,
Could anyone tell me howto transform my code so I can get the value on select to change the town so I can get the weather info?
<form class="form-group">
<select class="form-control" id="selectCountry">
<option>Select a country</option>
<option disabled="">_________</option>
<option value="Kabul,AF">Afghanistan</option>
<option value="Luanda,AO">Angola</option>
<option value="Canberra,AU">Australia</option>
<option value="Vienna,AT">Austria</option>
</select>
</form>
const key = '';
if(key=='') document.getElementById('temp').innerHTML = ('');
function weatherApp( name ) {
fetch('https://api.openweathermap.org/data/2.5/weather?q=' + name+ '&appid=' + key)
.then(function(resp) { return resp.json() })
.then(function(data) {
drawWeather(data);
})
.catch(function() {
// catch any errors
});
}
function drawWeather( d ) {
var celcius = Math.round(parseFloat(d.main.temp)-273.15);
var fahrenheit = Math.round(((parseFloat(d.main.temp)-273.15)*1.8)+32);
var description = d.weather[0].description;
document.getElementById('description').innerHTML = description;
document.getElementById('temp').innerHTML = celcius + '°';
document.getElementById('location').innerHTML = d.name;
if( description.indexOf('rain') > 0 ) {
document.body.className = 'rainy';
} else if( description.indexOf('cloud') > 0 ) {
document.body.className = 'cloudy';
} else if( description.indexOf('sunny') > 0 ) {
document.body.className = 'sunny';
} else {
document.body.className = 'clear';
}
}
window.onload = function() {
weatherApp( "Manchester" );
}