Solved

Sequentially call functions in jquery

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
Introduction JSON is an acronym for JavaScript Object Notation.  It is a text-string data transport mechanism, capable of representing simple or complex data structures in a consistent and easy-to-read manner.  Similar in concept to XML, but more e…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…

685 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