...

View Full Version : Global variables



csam0003
04-06-2009, 08:43 PM
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

jmrker
04-07-2009, 01:47 AM
What's wrong with the answers provided here? :confused:
http://www.webdeveloper.com/forum/showthread.php?t=206398

csam0003
04-07-2009, 02:47 AM
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

TinyScript
04-07-2009, 07:15 AM
What's wrong with the answers provided here? :confused:
http://www.webdeveloper.com/forum/showthread.php?t=206398

is he trying to make a closure?
http://www.hunlock.com/blogs/Closing_The_Book_On_Javascript_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.

csam0003
04-07-2009, 11:59 AM
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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum