The CreatorCon Call for Content is officially open! Get started here.

how to update variable inside callback function

Akki1
Tera Contributor

HI, I have defined variable outside and i want to update the value inside callback . How can i do it.

I have tried to explain my scenario using an example.

var name='abc';

if(user!=' '){

var x = g_form.getReference('user', callFunction);

function callFunction(x){

var managerName=x.manager;

name=name+"_" + managerName;

}

}

alert(name);     // I'm not getting the updated name it still shows abc 

//The goal I want to achieve is the variable to update the value and use it outside callFunction

 

22 REPLIES 22

Aman Kumar S
Kilo Patron

You can't do that, you are trying to fetch the value that is within the function(local) scope, you got to update the field inside the callback function only

Best Regards
Aman Kumar

But the variable is not in local scope na I'm justupdating the value?I hv further more code so I need the value outside

But since you are accessing the value from outside the callback function, it will still refer to global value that has been set, why can't you include rest of your code inside callback function only?

Best Regards
Aman Kumar

SumanthDosapati
Mega Sage
Mega Sage

Hi,

Why are you not writing as

var name='abc';

if(user!=' '){

var x = g_form.getReference('user', callFunction);
}

function callFunction(x){

var managerName=x.manager;

name=name+"_" + managerName;

}



alert(name);   

 

Regards,
Sumanth