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 9142549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:48:28+00:00 2026-06-17T09:48:28+00:00

Ok, so I have two files , index.html and functions.js (index.html correctly includes functions.js).

  • 0

Ok, so I have two files , index.html and functions.js (index.html correctly includes functions.js).

When clicking a button in the webpage, a function gets called in the functions file, which updates elements in the web-page (correctly) and attempts to set two global variables ( woind that by doingwindow.var1 and window.var2 . No errors so far in the web console.

After this function gets called, in the index.html I run a code of JS that attempts to read window.var1 and window.var2, but finds them both to be null.

Why is that ? Could you also please point me to some material regarding as to why this happens, not just the solution ?

EDIT
I am using jquery and jquery mobile.
The event handler that calls the two functions is

 $('#map').live('pageshow',function(){
            console.debug('clicked button, calling function');
            position(longitude,latitude); //sets the global vars
            initializeMap();
            console.debug('finished with map calling');
        });

and sits inside a document.ready() .

EDIT 2
I know am sure that the two functions happen sequentially, I am doing a console.log() at their entry points.

  • 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-17T09:48:29+00:00Added an answer on June 17, 2026 at 9:48 am

    I’m going out on a limb in the absence of full code…

    It could be that you’re declaring and setting these variables inside a function. Function scope means that they don’t exist outside of any function in which they are declared. The solution is to declare them (using the var keyword) outside of any function (i.e. at the top of the file), and set them inside the function.

    Otherwise, they’re not global.

    Forgive me if this is completely not the case.

    var myGlobal = 0;
    
    myFunction = function() {
        myGlobal = 42;
    }
    
    // myGlobal now is equal to 42
    

    Whereas…

    myFunction = function() {
        var myGlobal = 42;
    }
    
    // myGlobal now is null
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two web-sites and two files: provider.com/provide.js viewer.com/index.html viewer.com/index.html renders information to the
I have PHP page in subfolder, /subfolder. In root I have two files: index.html
I have two files php (gettable.php and index.php) the index file display the result
I have two files. index.php and cart.php. All my functions, connection to database, etc.
I have two files 1 - index.php 2 - main.php index.php call to main.php
i have two files:(localhost/template/) index.php template.php each time when i create an article(an article
I have two files client.php and server.php. The client file send a HTTP request
I have two files: domainList and config.cnf. The domainList file simply has a list
I have two files called file_utils.h and file_utils.cpp which contain some methods and variables
I have two files A - nodes_to_delete and B - nodes_to_keep . Each file

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.