Advertisement
enochmh2

full current skeleton

Apr 10th, 2015
198
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. <!DOCTYPE html>
  2.  
  3. <html lang="en">
  4. <head>
  5. <meta charset="utf-8">
  6. <title>Mini Project Template</title>
  7. </head>
  8.  
  9. <body>
  10. City <input type="text" id="inpSearch"> <input type="button" id="btnSearch" value="Search" onclick="search();">
  11. <div id="result"/>
  12.  
  13. <div id="temp"/>
  14.  
  15. <script>
  16. function search() {
  17.  
  18. var keyword = document.querySelector("#inpSearch").value;
  19.  
  20.  
  21. var baseUrl = "http://api.openweathermap.org/data/2.5/weather?q=";
  22. var url = baseUrl + keyword;
  23.  
  24.  
  25. var xmlhttp;
  26. if (window.XMLHttpRequest) { // code for IE7+, Firefox, Chrome, Opera, Safari
  27. xmlhttp=new XMLHttpRequest();
  28. } else {// code for IE6, IE5
  29. xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  30. }
  31. xmlhttp.onreadystatechange=function() {
  32. if (xmlhttp.readyState==4 && xmlhttp.status==200) {
  33. // 4. Display data
  34. display(JSON.parse(xmlhttp.responseText));
  35.  
  36.  
  37. }
  38. }
  39. xmlhttp.open("GET", url, true);
  40. xmlhttp.send();
  41. }
  42.  
  43. function display(data) {
  44.  
  45. document.querySelector("#result").innerHTML = "The " + document.querySelector("#inpSearch").text + data.weather[0].description;
  46. document.querySelector("#temp").innerHTML = "The current temperature of " + document.querySelector("#inpSearch").value + " is " + Math.round(data.main.temp - 273.15) + "°C";
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65. </script>
  66. </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement