my dog learned polymorphism*
The moose likes HTML, CSS and JavaScript and the fly likes Accessing a variable outside of a javascript function? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Accessing a variable outside of a javascript function?" Watch "Accessing a variable outside of a javascript function?" New topic
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: 15376
    
    6
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: 15376
    
    6
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: 15376
    
    6
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.
 
jQuery in Action, 2nd edition
 
subject: Accessing a variable outside of a javascript function?