Click to See Complete Forum and Search --> : variables in functions


flashgroover
09-03-2003, 07:17 PM
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="javascript:launchCenter(f,m);"></a>');

}else{

bla bla

}
}

my problem is that the computer says that the variable "f" in (f,m) is not defined. when i give it a value like '1' ('1',m) it then says variable "m" 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

Charles
09-03-2003, 07:40 PM
When you define a variable inside of a function or method and you precede it with "var" the variable is actually a property of the call object and is destroyed when the function or method returns. You want these variables to persist so you'll need to make them properties of something else. Omitting the "var" will make them properties of the window object.