Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Mar 2009
    Posts
    45
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Global variables

    Hi,

    I have a custom toolbar in firefox which calls js functions from an external javascript file.

    In the js file I declared a global variable:

    var test;

    function testfn1()
    {
    test = "testingtesting";
    }


    function testfn2()
    {
    alert(test);
    }

    I first call the function testfn1 when i click on a button on the toolbar and then when I click on another button on the toolbar, it calls testfn2. However I noticed that the function testfn2() alerts "undefined". When I embed all this in the html page, it works fine; however in the external js it seems its not working.

    any ideas?

    Thanks
    Last edited by csam0003; 04-07-2009 at 12:34 AM.

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,148
    Thanks
    39
    Thanked 506 Times in 500 Posts

    Lightbulb

    What's wrong with the answers provided here?
    http://www.webdeveloper.com/forum/sh...d.php?t=206398

  • #3
    New Coder
    Join Date
    Mar 2009
    Posts
    45
    Thanks
    3
    Thanked 0 Times in 0 Posts
    hi jmrker,

    please check out that link again. I made a new post. It seems I can not call the function using onmouseover???


    Thanks

    kind regards

  • #4
    Regular Coder
    Join Date
    Mar 2009
    Location
    Portland Oregon
    Posts
    690
    Thanks
    44
    Thanked 63 Times in 62 Posts
    Quote Originally Posted by jmrker View Post
    What's wrong with the answers provided here?
    http://www.webdeveloper.com/forum/sh...d.php?t=206398
    is he trying to make a closure?
    http://www.hunlock.com/blogs/Closing...cript_Closures
    Csam, check this out. I think this is what you want to see. I'm not sure if you'll be able to use the mouse event you desire, but have a look at the scripting for a clear example of what it seems you are trying to do, which is attach a function to an event.

  • #5
    New Coder
    Join Date
    Mar 2009
    Posts
    45
    Thanks
    3
    Thanked 0 Times in 0 Posts
    thanks Tinyscript!

    I realized that it is an issue with the xul file I have. Basically I have testfn1() called when the user hovers over some text (i.e. onmouseover) on a page and then I use an Xul button to call testfn2(). It seems the global variable resets.

    anyways I managed a workaround. I thank you all for your input and help

    kind regards

    chris


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •