javascript global variables

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • localp
    New Member
    • Jun 2008
    • 8

    javascript global variables

    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
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    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

    Comment

    • rnd me
      Recognized Expert Contributor
      • Jun 2007
      • 427

      #3
      from anywhere, window.myVariab le will create/refer to a global named myVariable.

      Comment

      Working...