| Author |
Accessing a variable outside of a javascript function?
|
Koldo Urrutia
Ranch Hand
Joined: Dec 16, 2011
Posts: 85
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
Appears to be asynchronous callback so it is not possible to read it inline, JavaScript does not have wait.
Eric
|
 |
Koldo Urrutia
Ranch Hand
Joined: Dec 16, 2011
Posts: 85
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
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
Joined: Dec 16, 2011
Posts: 85
|
|
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
Joined: Nov 08, 2001
Posts: 15357
|
|
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
Joined: Dec 16, 2011
Posts: 85
|
|
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
Joined: Dec 16, 2011
Posts: 85
|
|
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
Joined: Dec 16, 2011
Posts: 85
|
|
Ive tried already a few different ways but to no avail. I need some help
|
 |
Koldo Urrutia
Ranch Hand
Joined: Dec 16, 2011
Posts: 85
|
|
I currently have this:
Which works if I put the alert. If I dont put it, its always the same value.
|
 |
 |
|
|
subject: Accessing a variable outside of a javascript function?
|
|
|