Javascript updating global variable from function not working
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/13016498/javascript-global-variable-is-not-updating">Javascript global variable is not updating</a>  </p>
</blockquote>



<p>I have this site that I am making. I want to update a global variable from another function. The global variable statCheck is initialized to 0. I created 2 functions, 1 to update the global variable and display the new value by alert, and second a function that will just alert the new value of the updated global variable. The problem now is when I call the first function, it alerts the new updated value, but when I call the second function it alerts the original value which is zero. Here's my code:</p>

<pre><code>var statCheck=0;

var users=new Array();
var password=new Array();
users[0]="clydewinux";
password[0]="moonfang";
users[1]="freddipasquale";
password[1]="evastar182";

function verifyInput(){
var u=login.username.value;
var p=login.password.value;
for (var c=0;c&lt;=1;c++){
    if(u===users[c]&amp;&amp;p===password[c])
        { 
        statCheck=1; 
        alert(statCheck);
        window.open("login.htm", '_self'); 
        break;}
    else
        {document.getElementById("username").value="Invalid username..."; 
        window.open("home.htm", '_self'); 
        break;}
    }

        }

function logout(){
alert(statCheck);
window.open("home.htm", '_self');
}
</code></pre>

<p>*Note; function verifyInput() is the first function, and function logout is the second.</p>
