Solved

Sequentially call functions in jquery

Posted on 2012-04-08
2
208 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

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 Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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)

632 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