Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Sequentially call functions in jquery

Posted on 2012-04-08
2
Medium Priority
?
211 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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

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…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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…

688 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