Solved

Sequentially call functions in jquery

Posted on 2012-04-08
2
202 Views
Last Modified: 2012-05-10
Hi

I have two functions in jquery. They are called like this:

Func1
Func2

The trouble is I only want Func2 to be called when Func1 has completed.

Any help appreciated

Thanks
0
Comment
Question by:jellydeal
2 Comments
 
LVL 23

Expert Comment

by:basicinstinct
ID: 37821828
javascript is single threaded - they will be called in sequence no matter what you do
0
 
LVL 20

Accepted Solution

by:
BuggyCoder earned 500 total points
ID: 37821860
using javascript callback functions, you can do this as given below:-
function Func1(y, func2)
{
//process Func1 function
var x =10;
x=x+y;

alert('Func1 has done processing, press ok to call func2 now');

func2();//calling func2 function after func1 has finished...
}

function Func2()
{
alert('Func2 is called');
}
//calling func1 and passing reference to func2 to be used as callback function
Func1(5,Func2);

Open in new window

0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

I have answered several questions lately that were solved utilizing the power of jQuery's AJAX functions, so I thought I would write an article demonstrating the ease of use. Why should I use jQuery as opposed to regular JavaScript? Now I know…
Introduction If you're like most people, you have occasionally made a typographical error when you're entering information into an online form.  And to your consternation, the browser remembers the error, and offers to autocomplete your future entr…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now