By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,501 Members | 1,245 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,501 IT Pros & Developers. It's quick & easy.

javascript global variables

P: 8
i created a javascript function that would calculate the total values of an array . (just addition) - and it did work and display correctly in that function.

i initialized the variable where i saved the total at the top of the javascript page (out side the function and initialized it to 0)

[HTML]total += parseInt(price[sha]);[/HTML]

but when i created another function in the intension of using that value ( the total which i calculated in the above function), i am getting a zero instead the value which was calculated .. ( i got the zero bcoz i initialized that variable to 0) .. even whe i removed the 0, it didnt work ...

how can i access the value of the total variable which i calculated above .. ?

cant we have global or universal variables in javascripts ?

is there any other technique where i can access that variable ?

plzzz provide me with a code ....

plzz help
Jun 12 '08 #1
Share this Question
Share on Google+
2 Replies


gits
Expert Mod 5K+
P: 5,390
of course you have private and global variables ... show the entire code that is not working ... variable scope is such a basic issue that a basic tutorial like this is a good starting point ...

kind regards
Jun 12 '08 #2

rnd me
Expert 100+
P: 427
from anywhere, window.myVariable will create/refer to a global named myVariable.
Jun 14 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.