Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variables in functions

Status
Not open for further replies.

cesarcesar

Programmer
Mar 5, 2003
30
hello all,

this is the important part of my script:

-----------------------------------------

function matrix(){

var date = 4;

if(date == 4){

var f = 'idf_loader.htm';
var m = 'webcast';

document.write('<a href=&quot;javascript:launchCenter(f,m);&quot;></a>');

}else{

bla bla

}
}

my problem is that the computer says that the variable &quot;f&quot; in (f,m) is not defined. when i give it a value like '1' ('1',m) it then says variable &quot;m&quot; is not defined. why is this? does it have to do with any of these factors below?

1. the function launchCenter is not in the same JS script as the above function matrix. but both pages holding scripts are called in the <head> of HTML page.

2. or if because it has anything to do with it being a function within a function that calls to an outside function? not sure

Thanks for any reply's.

cesar
 
your problem is that your variables f and m do not have global scope. You declare them inside your matrix() function, which means that every time the function is called they are created and once it finishes running they are destroyed.

googled this.. might help:

If instead of document.writing the variable names you just want to write what's IN them you need to change your line like so:
Code:
document.write('<a href=&quot;javascript:launchCenter(' + f + ',' + m + ');&quot;></a>');

Posting code? Wrap it with code tags: [ignore]
Code:
[/ignore][code]CodeHere
[ignore][/code][/ignore].
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top