Tuesday, 15 May 2012

javascript - Global Vairable wont change values -



javascript - Global Vairable wont change values -

so have 2 javascript files in html page

<script src="file1.js"> </script> <script src="file2.js"> </script>

in first file have global variable.

var x="-1";

and function

function loaduser() { x="1"; }

now, in sec file have function

function whoislog() { alert(x); }

the problem is, x wont alter value if cookie results brings expected value. need x new value in sec file. alert results "-1".

i have confirmed loaduser() first function run.

to sure it's global assign window obj.

window.x = -1;

or post entire code in jsfiddle.

javascript html

No comments:

Post a Comment