variable scope - Accessing value of global variable ???

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hash4sp
    New Member
    • Aug 2007
    • 55

    variable scope - Accessing value of global variable ???

    Hello readers,

    How do I access value of a global variable in a function.

    Code:
    var UserName; //declared global 
    
    function1(UName) // this function is called onLoad event and UName is passed 
    {
    UserName = UName;
    }
    
    function2()
    {
    -->//how to get the value of UserName here which is set in above function
    }
    I tried using window.UserName But it doesnt work.
    I think I am going wrong somewhere....

    any help or suggestions plz..

    Thanks & regards,
  • hsriat
    Recognized Expert Top Contributor
    • Jan 2008
    • 1653

    #2
    Originally posted by hash4sp
    Hello readers,

    How do I access value of a global variable in a function.

    Code:
    var UserName; //declared global 
    
    function1(UName) // this function is called onLoad event and UName is passed 
    {
    UserName = UName;
    }
    
    function2()
    {
    -->//how to get the value of UserName here which is set in above function
    }
    I tried using window.UserName But it doesnt work.
    I think I am going wrong somewhere....

    any help or suggestions plz..

    Thanks & regards,

    Use it as UserName only.

    Comment

    Working...