I create weather box in my website, when i call javascript function normal, it's normal. But when i call this function by event, it has problem, help me, thanks you very much!
<script type="text/javascript">
function showWeatherCallback(data) {
var channel = data.query.results.weather.rss.channel,
img = channel.item.description.match(/http:\/\/[^"']*/),
html = '<strong>City : </strong> ' + channel.location.city + '<br />' +
'<img style="vertical-align:bottom" height="52" width="52" src="' + img + '" /> '+
'<span style="font-size:44px">' + channel.item.condition.temp + '°' +channel.units.temperature +'</span><br />' +
'<strong>Do am:</strong> ' + channel.atmosphere.humidity + '%<br />' +
'<strong>Nhiet do thap:</strong> ' + channel.item.forecast[0].low+ '°' +channel.units.temperature +'<br />' +
'<strong>Nhiet do cao:</strong> ' + channel.item.forecast[0].high+ '°' +channel.units.temperature +'<br />' +
'<strong>Nhiet do thap ngay mai:</strong> ' + channel.item.forecast[1].low+ '°' +channel.units.temperature +'<br />' +
'<strong>Nhiet do cao ngay mai:</strong> ' + channel.item.forecast[1].high+ '°' +channel.units.temperature +'<br />' +
'<strong>Suc gio:</strong> ' + channel.wind.speed + ' km/h <br />';
document.write(html);
}
function showWeather(location,tempType) {
var baseUrl = 'http://query.yahooapis.com/v1/public/yql?q=';
var q = 'use "http://github.com/yql/yql-tables/raw/master/weather/weather.bylocation.xml" as we;' +
'select * from we where location="' + location + '" and unit="'+ tempType +'"';
var url = baseUrl + encodeURIComponent(q) + '&format=json&diagnostics=false&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=showWeatherCallback';
document.write('<script type="text/javascript" src="' + url + '"></' + 'script>');
}
</script>
<form>
<select onchange ="showWeather('hanoi, vietnam', 'c');">
<option selected="selected" value="nhatrang, vietnam">Nha trang</option>
<option id = 'test1' value="hanoi, vietnam">Ha noi</option>
<option value="pleaiku, vietnam">Pleiku</option>
<option value="hochiminh, vietnam">TP HCM</option>
</select>
<script type="text/javascript">showWeather('hochiminh, vietnam', 'c');</script>
</form>
by
0 Replies