openweathermap weather data by zip code not working?









up vote
1
down vote

favorite












i need to make it so that when a zip code is typed into the box and the submit button is clicked, the name of the city shows up under it. when i click the button after putting a zip code the city name doesn't show up. it says the error is that wallOfText is not a function but i'm not sure how to fix it. any help would be appreciated!! here's the code:






<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<meta charset="UTF-8">
<title>Example</title>
</head>
<body>
Enter your zip code:<br><input type="text" id="zipBox" name="zipCode"><br><br>
<button onclick="weatherFunction()">Submit</button>
<p id="result"></p>
<script>
function weatherFunction()
var zip = document.getElementById("zipBox").value;
jQuery(document).ready(function ($)
$.ajax(
url: "http://api.openweathermap.org/data/2.5/weather?zip=" +zip+ ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
dataType: "jsonp",
success: function (wallOfText)
city = wallOfText("name");
if (zip != null)
document.getElementById("result").innerHTML = wallOfText;



);
);

</script>
</body>
</html>












share|improve this question







New contributor




kyle z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.























    up vote
    1
    down vote

    favorite












    i need to make it so that when a zip code is typed into the box and the submit button is clicked, the name of the city shows up under it. when i click the button after putting a zip code the city name doesn't show up. it says the error is that wallOfText is not a function but i'm not sure how to fix it. any help would be appreciated!! here's the code:






    <!DOCTYPE html>
    <html lang="en">
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <meta charset="UTF-8">
    <title>Example</title>
    </head>
    <body>
    Enter your zip code:<br><input type="text" id="zipBox" name="zipCode"><br><br>
    <button onclick="weatherFunction()">Submit</button>
    <p id="result"></p>
    <script>
    function weatherFunction()
    var zip = document.getElementById("zipBox").value;
    jQuery(document).ready(function ($)
    $.ajax(
    url: "http://api.openweathermap.org/data/2.5/weather?zip=" +zip+ ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
    dataType: "jsonp",
    success: function (wallOfText)
    city = wallOfText("name");
    if (zip != null)
    document.getElementById("result").innerHTML = wallOfText;



    );
    );

    </script>
    </body>
    </html>












    share|improve this question







    New contributor




    kyle z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





















      up vote
      1
      down vote

      favorite









      up vote
      1
      down vote

      favorite











      i need to make it so that when a zip code is typed into the box and the submit button is clicked, the name of the city shows up under it. when i click the button after putting a zip code the city name doesn't show up. it says the error is that wallOfText is not a function but i'm not sure how to fix it. any help would be appreciated!! here's the code:






      <!DOCTYPE html>
      <html lang="en">
      <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <meta charset="UTF-8">
      <title>Example</title>
      </head>
      <body>
      Enter your zip code:<br><input type="text" id="zipBox" name="zipCode"><br><br>
      <button onclick="weatherFunction()">Submit</button>
      <p id="result"></p>
      <script>
      function weatherFunction()
      var zip = document.getElementById("zipBox").value;
      jQuery(document).ready(function ($)
      $.ajax(
      url: "http://api.openweathermap.org/data/2.5/weather?zip=" +zip+ ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
      dataType: "jsonp",
      success: function (wallOfText)
      city = wallOfText("name");
      if (zip != null)
      document.getElementById("result").innerHTML = wallOfText;



      );
      );

      </script>
      </body>
      </html>












      share|improve this question







      New contributor




      kyle z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      i need to make it so that when a zip code is typed into the box and the submit button is clicked, the name of the city shows up under it. when i click the button after putting a zip code the city name doesn't show up. it says the error is that wallOfText is not a function but i'm not sure how to fix it. any help would be appreciated!! here's the code:






      <!DOCTYPE html>
      <html lang="en">
      <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <meta charset="UTF-8">
      <title>Example</title>
      </head>
      <body>
      Enter your zip code:<br><input type="text" id="zipBox" name="zipCode"><br><br>
      <button onclick="weatherFunction()">Submit</button>
      <p id="result"></p>
      <script>
      function weatherFunction()
      var zip = document.getElementById("zipBox").value;
      jQuery(document).ready(function ($)
      $.ajax(
      url: "http://api.openweathermap.org/data/2.5/weather?zip=" +zip+ ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
      dataType: "jsonp",
      success: function (wallOfText)
      city = wallOfText("name");
      if (zip != null)
      document.getElementById("result").innerHTML = wallOfText;



      );
      );

      </script>
      </body>
      </html>








      <!DOCTYPE html>
      <html lang="en">
      <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <meta charset="UTF-8">
      <title>Example</title>
      </head>
      <body>
      Enter your zip code:<br><input type="text" id="zipBox" name="zipCode"><br><br>
      <button onclick="weatherFunction()">Submit</button>
      <p id="result"></p>
      <script>
      function weatherFunction()
      var zip = document.getElementById("zipBox").value;
      jQuery(document).ready(function ($)
      $.ajax(
      url: "http://api.openweathermap.org/data/2.5/weather?zip=" +zip+ ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
      dataType: "jsonp",
      success: function (wallOfText)
      city = wallOfText("name");
      if (zip != null)
      document.getElementById("result").innerHTML = wallOfText;



      );
      );

      </script>
      </body>
      </html>





      <!DOCTYPE html>
      <html lang="en">
      <head>
      <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
      <meta charset="UTF-8">
      <title>Example</title>
      </head>
      <body>
      Enter your zip code:<br><input type="text" id="zipBox" name="zipCode"><br><br>
      <button onclick="weatherFunction()">Submit</button>
      <p id="result"></p>
      <script>
      function weatherFunction()
      var zip = document.getElementById("zipBox").value;
      jQuery(document).ready(function ($)
      $.ajax(
      url: "http://api.openweathermap.org/data/2.5/weather?zip=" +zip+ ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
      dataType: "jsonp",
      success: function (wallOfText)
      city = wallOfText("name");
      if (zip != null)
      document.getElementById("result").innerHTML = wallOfText;



      );
      );

      </script>
      </body>
      </html>






      javascript jquery weather openweathermap






      share|improve this question







      New contributor




      kyle z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.











      share|improve this question







      New contributor




      kyle z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      share|improve this question




      share|improve this question






      New contributor




      kyle z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.









      asked Nov 9 at 16:19









      kyle z

      82




      82




      New contributor




      kyle z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.





      New contributor





      kyle z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






      kyle z is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote



          accepted










          The issue you have is that you're attempting to call wallOfText like it's a function, when in fact it's the object which has been deserialised from the response of the AJAX call. As such, you need to access the object's name property to set the city variable, then use that to set the text() of the #result element.



          Note that the document.ready handler within the function is redundant, and you should be doing the zip value validation before you make the request. I also updated the logic to use jQuery to bind the event handler on the button instead of the outdated onclick attribute. Try this:






          jQuery(function() 
          $('#send').click(function()
          var zip = $("#zipBox").val();
          if (zip !== '')
          $.ajax(
          url: "http://api.openweathermap.org/data/2.5/weather?zip=" + zip + ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
          dataType: "jsonp",
          success: function(wallOfText)
          var city = wallOfText.name;
          $("#result").text(city);

          );

          );
          );

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          Enter your zip code:<br>
          <input type="text" id="zipBox" name="zipCode" value="90210" /><br /><br />
          <button type="button" id="send">Submit</button>
          <p id="result"></p>








          share|improve this answer






















          • it works! thank you so much!!
            – kyle z
            Nov 9 at 17:20










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );






          kyle z is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229506%2fopenweathermap-weather-data-by-zip-code-not-working%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote



          accepted










          The issue you have is that you're attempting to call wallOfText like it's a function, when in fact it's the object which has been deserialised from the response of the AJAX call. As such, you need to access the object's name property to set the city variable, then use that to set the text() of the #result element.



          Note that the document.ready handler within the function is redundant, and you should be doing the zip value validation before you make the request. I also updated the logic to use jQuery to bind the event handler on the button instead of the outdated onclick attribute. Try this:






          jQuery(function() 
          $('#send').click(function()
          var zip = $("#zipBox").val();
          if (zip !== '')
          $.ajax(
          url: "http://api.openweathermap.org/data/2.5/weather?zip=" + zip + ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
          dataType: "jsonp",
          success: function(wallOfText)
          var city = wallOfText.name;
          $("#result").text(city);

          );

          );
          );

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          Enter your zip code:<br>
          <input type="text" id="zipBox" name="zipCode" value="90210" /><br /><br />
          <button type="button" id="send">Submit</button>
          <p id="result"></p>








          share|improve this answer






















          • it works! thank you so much!!
            – kyle z
            Nov 9 at 17:20














          up vote
          0
          down vote



          accepted










          The issue you have is that you're attempting to call wallOfText like it's a function, when in fact it's the object which has been deserialised from the response of the AJAX call. As such, you need to access the object's name property to set the city variable, then use that to set the text() of the #result element.



          Note that the document.ready handler within the function is redundant, and you should be doing the zip value validation before you make the request. I also updated the logic to use jQuery to bind the event handler on the button instead of the outdated onclick attribute. Try this:






          jQuery(function() 
          $('#send').click(function()
          var zip = $("#zipBox").val();
          if (zip !== '')
          $.ajax(
          url: "http://api.openweathermap.org/data/2.5/weather?zip=" + zip + ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
          dataType: "jsonp",
          success: function(wallOfText)
          var city = wallOfText.name;
          $("#result").text(city);

          );

          );
          );

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          Enter your zip code:<br>
          <input type="text" id="zipBox" name="zipCode" value="90210" /><br /><br />
          <button type="button" id="send">Submit</button>
          <p id="result"></p>








          share|improve this answer






















          • it works! thank you so much!!
            – kyle z
            Nov 9 at 17:20












          up vote
          0
          down vote



          accepted







          up vote
          0
          down vote



          accepted






          The issue you have is that you're attempting to call wallOfText like it's a function, when in fact it's the object which has been deserialised from the response of the AJAX call. As such, you need to access the object's name property to set the city variable, then use that to set the text() of the #result element.



          Note that the document.ready handler within the function is redundant, and you should be doing the zip value validation before you make the request. I also updated the logic to use jQuery to bind the event handler on the button instead of the outdated onclick attribute. Try this:






          jQuery(function() 
          $('#send').click(function()
          var zip = $("#zipBox").val();
          if (zip !== '')
          $.ajax(
          url: "http://api.openweathermap.org/data/2.5/weather?zip=" + zip + ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
          dataType: "jsonp",
          success: function(wallOfText)
          var city = wallOfText.name;
          $("#result").text(city);

          );

          );
          );

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          Enter your zip code:<br>
          <input type="text" id="zipBox" name="zipCode" value="90210" /><br /><br />
          <button type="button" id="send">Submit</button>
          <p id="result"></p>








          share|improve this answer














          The issue you have is that you're attempting to call wallOfText like it's a function, when in fact it's the object which has been deserialised from the response of the AJAX call. As such, you need to access the object's name property to set the city variable, then use that to set the text() of the #result element.



          Note that the document.ready handler within the function is redundant, and you should be doing the zip value validation before you make the request. I also updated the logic to use jQuery to bind the event handler on the button instead of the outdated onclick attribute. Try this:






          jQuery(function() 
          $('#send').click(function()
          var zip = $("#zipBox").val();
          if (zip !== '')
          $.ajax(
          url: "http://api.openweathermap.org/data/2.5/weather?zip=" + zip + ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
          dataType: "jsonp",
          success: function(wallOfText)
          var city = wallOfText.name;
          $("#result").text(city);

          );

          );
          );

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          Enter your zip code:<br>
          <input type="text" id="zipBox" name="zipCode" value="90210" /><br /><br />
          <button type="button" id="send">Submit</button>
          <p id="result"></p>








          jQuery(function() 
          $('#send').click(function()
          var zip = $("#zipBox").val();
          if (zip !== '')
          $.ajax(
          url: "http://api.openweathermap.org/data/2.5/weather?zip=" + zip + ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
          dataType: "jsonp",
          success: function(wallOfText)
          var city = wallOfText.name;
          $("#result").text(city);

          );

          );
          );

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          Enter your zip code:<br>
          <input type="text" id="zipBox" name="zipCode" value="90210" /><br /><br />
          <button type="button" id="send">Submit</button>
          <p id="result"></p>





          jQuery(function() 
          $('#send').click(function()
          var zip = $("#zipBox").val();
          if (zip !== '')
          $.ajax(
          url: "http://api.openweathermap.org/data/2.5/weather?zip=" + zip + ",us&appid=b3456f9acbfa64fc4495e6696ecdc9a5",
          dataType: "jsonp",
          success: function(wallOfText)
          var city = wallOfText.name;
          $("#result").text(city);

          );

          );
          );

          <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
          Enter your zip code:<br>
          <input type="text" id="zipBox" name="zipCode" value="90210" /><br /><br />
          <button type="button" id="send">Submit</button>
          <p id="result"></p>






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 9 at 16:36

























          answered Nov 9 at 16:31









          Rory McCrossan

          238k29200243




          238k29200243











          • it works! thank you so much!!
            – kyle z
            Nov 9 at 17:20
















          • it works! thank you so much!!
            – kyle z
            Nov 9 at 17:20















          it works! thank you so much!!
          – kyle z
          Nov 9 at 17:20




          it works! thank you so much!!
          – kyle z
          Nov 9 at 17:20










          kyle z is a new contributor. Be nice, and check out our Code of Conduct.









           

          draft saved


          draft discarded


















          kyle z is a new contributor. Be nice, and check out our Code of Conduct.












          kyle z is a new contributor. Be nice, and check out our Code of Conduct.











          kyle z is a new contributor. Be nice, and check out our Code of Conduct.













           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53229506%2fopenweathermap-weather-data-by-zip-code-not-working%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Kleinkühnau

          Makov (Slowakei)

          Deutsches Schauspielhaus