/    Sign up×
Community /Pin to ProfileBookmark

variables in functions

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

    to post a comment
    JavaScript

    1 Comments(s)

    Copy linkTweet thisAlerts:
    @CharlesSep 04.2003 — [font=georgia]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.[/font]
    ×

    Success!

    Help @flashgroover spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...