javascript onComplete or call back problem

K so i have a problem i have two functions that i want ran but although javascript runs things sequentially it continues on before the first finishes.  So i need someone to show me how i could use a call back, or some kind of onComplete method to wait until the first function is ran before the second one begins running
<script>

function goTime()
{
            firstFunction();
            secondFunction(); 

}

function firstFunction()
{
}

function secondFunction()
{

}

Open in new window

LVL 4
Brant SnowAsked:
Who is Participating?
 
MangagmCommented:
It does execute firstFunction first, but if that function calls something else and it takes a long to proccess, the goTime function will continue its proccess calling secondFunction even if first hasnt finished, you usually dont notice this because all actions are done to quick, but it does happens, especially when using another library or special components that prolly make ajax transactions.
0
 
sdrouinsCommented:
I think your doing something wrong....
javascript will not call your second function until the first one is finish?

javascript is not asychronous
0
 
MangagmCommented:
@sdrouins yes it is, it can be used asychronous or not

@thawts I'd need to see what is what your functions do to give a more accurate answer, but most likely you can solve it using the setTimeout() :

http://www.w3schools.com/jsref/met_win_settimeout.asp 

or a component that has the oncomplete method which depends on what techlnology are you using, but richfaces and icefaces are some examples of implementations that have components with oncomplete, cant use them if your working with .net tho, so maybe if you tell me what technolgy ur working with? (.jsp,.asp...) , gl
0
 
sdrouinsCommented:
maybe I dont understand I question, but this guy dont want asychronous call..... I want it sequential? no?

by default firstFunction will be execute et after it finish function2 will be call?
0
 
Brant SnowAuthor Commented:
s
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.