Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8721451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T07:13:27+00:00 2026-06-13T07:13:27+00:00

I want to show the weather on my website. I have some javascript code

  • 0

I want to show the weather on my website. I have some javascript code like

$(function () {

    // Specify the ZIP/location code and units (f or c)
    //var loc = '10001'; // or e.g. SPXX0050
    //var u = 'f';

    var loc = 'TUXX0002';
    //var loc = 'TUXX0014';
    var u = 'c';
    //var locA = 'TUXX0002';
    //var locI = 'TUXX0015';


    var query = "SELECT item.condition FROM weather.forecast WHERE location='" + loc + "' AND u='" + u + "'";
    var cacheBuster = Math.floor((new Date().getTime()) / 1200 / 1000);
    var url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&format=json&_nocache=' + cacheBuster;

    window['wxCallback'] = function (data) {
        var info = data.query.results.channel.item.condition;
        $('#wxIcon').css({
            backgroundPosition: '-' + (61 * info.code) + 'px 0'
        }).attr({
            title: info.text
        });
        $('#wxIcon2').append('<img src="http://l.yimg.com/a/i/us/we/52/' + info.code + '.gif" width="34" height="34" title="' + info.text + '" />');
        $('#wxTemp').html(info.temp + '&deg;' + (u.toUpperCase()));
    };

    $.ajax({
        url: url,
        dataType: 'jsonp',
        cache: true,
        jsonpCallback: 'wxCallback'
    });

});

For now it shows only one location. (with loc variable). I want to add a dropdown or something like a change location link. Than if user selects ‘A’ location it shows ‘A location’s weather’ etc. I added a dropdown item. Here is the code.

<select id="wxCombo">
   <option value="istanbul">istanbul</option>
   <option value="ankara">ankara</option>
   <option value="izmir">izmir</option>     
</select>

Than I add some javascript code for change function, on the same javascript page.

var wxCombo = $("#wxCombo").val(); 
    $("#wxCombo").change(function() 
    { 
        if (wxCombo == 'Ankara')
        {
            loc 'TUXX0002';     
        }
    });

It didn’t worked. I need some guide for fixing this issue.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T07:13:28+00:00Added an answer on June 13, 2026 at 7:13 am

    Here’s a few things I would change.

    First off, declare a function that will update the weather information, based on location:

    function updateWeather(loc, u)
    {
        var query = "SELECT item.condition \
            FROM weather.forecast \
            WHERE location='" + loc + "' AND u='" + u + "'",
        url = 'http://query.yahooapis.com/v1/public/yql?q=' + encodeURIComponent(query) + '&format=json';
    
        $.ajax({
            url: url,
            dataType: 'jsonp', // this automatically disables cache too
            success: function(data) {
                var info = data.query.results.channel.item.condition;
                $('#wxIcon').css({
                    backgroundPosition: '-' + (61 * info.code) + 'px 0'
                }).attr({
                    title: info.text
                });
                $('#wxIcon2').append('<img src="http://l.yimg.com/a/i/us/we/52/' + info.code + '.gif" width="34" height="34" title="' + info.text + '" />');
                $('#wxTemp').html(info.temp + '&deg;' + (u.toUpperCase()));
            }
        });
    }
    

    Then, hook this into the .change() handler:

    $("#wxCombo").change(function() { 
        var country = $(this).val();
    
        if (country == 'ankara') {
            updateWeather('TUXX0002', 'C');
        }
        // etc.
    });
    

    Demo: http://jsfiddle.net/ZF3aW/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want show tooltip with image tag and i have written code like below
I want to show some climate graphs and historical weather data for specific places
I have long page. I want show some info, so when user scroll page,
I want to to show the current city & weather in screen like this
I want to show the weather in my GWT application. I have seen several
I want to show a welcome screen as well as some basic tutorials of
I want show the iphone keyboard. How can I write the code (programmatically) to
I want show weather information from xml to this URL: http://www.google.com/ig/api?weather=roma&hl=it using this script:
I want to implement weather information which will show me results that depends on
I want to show some information in the middle of a call in that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.