Web Analytics Made Easy -
StatCounter Global variables - CodingForum

Announcement

Collapse
No announcement yet.

Global variables

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new 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; Apr 6, 2009, 06:34 PM.

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

    Comment


    • #3
      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

      Comment


      • #4
        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.

        Comment


        • #5
          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

          Comment

          Working...
          X