Solved

Sequentially call functions in jquery

Posted on 2012-04-08
2
204 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hi all! Recently there was EE question and the person wanted to have a multi-column textbox <div> selection, so as a first step to answer I provided a link but that was not complete with JavaScript selection, but had a good style sheet. So as a ques…
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)

803 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