• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Accessing a variable outside of a javascript function?

 
Koldo Urrutia
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello

I have the following and I want to access the variable outside of that function.

The code is:



Ive tried two solutions, neither of them work:








Thanks!
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Appears to be asynchronous callback so it is not possible to read it inline, JavaScript does not have wait.

Eric
 
Koldo Urrutia
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Appears to be asynchronous callback so it is not possible to read it inline, JavaScript does not have wait.

Eric

Well there has to be some way to get it, right? What method can I use to get the value?


Thank you!
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to break up your code into two parts, request to get the variable and than when the callback is returned fire off the next step.

Eric
 
Koldo Urrutia
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:You need to break up your code into two parts, request to get the variable and than when the callback is returned fire off the next step.

Eric

I have no idea where to even start or what to look for.

Do you mind helping me out please?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basic example of what you expect to happen



What is actually happening:


What you need to do is break it up into two parts.


 
Koldo Urrutia
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Basic example of what you expect to happen



What is actually happening:


What you need to do is break it up into two parts.




Thank you for putting a example at least

My main "issue" is what is "callback(a)"??? That isnt declared anywhere. Thats where I think Im getting lost.

That said, you are telling me to do something like this:






Would that code work???
 
Koldo Urrutia
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Koldo Urrutia wrote:
Thank you for putting a example at least

My main "issue" is what is "callback(a)"??? That isnt declared anywhere. Thats where I think Im getting lost.

That said, you are telling me to do something like this:






Would that code work???


Did not work....
 
Koldo Urrutia
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ive tried already a few different ways but to no avail. I need some help
 
Koldo Urrutia
Ranch Hand
Posts: 85
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I currently have this:


Which works if I put the alert. If I dont put it, its always the same value.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic