Go Back   CodingForums.com > :: Client side development > JavaScript programming > DOM and JSON scripting

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-06-2009, 07:43 PM   PM User | #1
csam0003
New Coder

 
Join Date: Mar 2009
Posts: 45
Thanks: 3
Thanked 0 Times in 0 Posts
csam0003 is an unknown quantity at this point
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-06-2009 at 11:34 PM..
csam0003 is offline   Reply With Quote
Old 04-07-2009, 12:47 AM   PM User | #2
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,762
Thanks: 29
Thanked 452 Times in 446 Posts
jmrker will become famous soon enough
Lightbulb

What's wrong with the answers provided here?
http://www.webdeveloper.com/forum/sh...d.php?t=206398
jmrker is offline   Reply With Quote
Old 04-07-2009, 01:47 AM   PM User | #3
csam0003
New Coder

 
Join Date: Mar 2009
Posts: 45
Thanks: 3
Thanked 0 Times in 0 Posts
csam0003 is an unknown quantity at this point
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
csam0003 is offline   Reply With Quote
Old 04-07-2009, 06:15 AM   PM User | #4
TinyScript
Regular Coder

 
Join Date: Mar 2009
Location: Portland Oregon
Posts: 690
Thanks: 44
Thanked 63 Times in 62 Posts
TinyScript is on a distinguished road
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.
TinyScript is offline   Reply With Quote
Old 04-07-2009, 10:59 AM   PM User | #5
csam0003
New Coder

 
Join Date: Mar 2009
Posts: 45
Thanks: 3
Thanked 0 Times in 0 Posts
csam0003 is an unknown quantity at this point
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
csam0003 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:10 PM.


Advertisement
Log in to turn off these ads.