Reputation: 11468
If I have one function which binds some buttons to another function, How can I execute some codes in the same function only after the button is clicked? For example, in below code, button.onclick assigns funct2(this.value) to the button and goes below in the function to execute the remaining code. What I want to achieve is to halt the execution till the some click event happens.
function funct1(){
//some other codes
button.onclick=function(){funct2(this.value)};
//CODES TO BE EXECUTED AFTER THE FUNCT2 RESPONDS TO SOME USER CLICK
function funct2(){
//some codes
}
Upvotes: 2
Views: 641
Reputation: 2930
Whatever code you need to be executed onclick, you must put in funct2
callback. There is no other way to temporarily 'halt' the execution of javascript and have it restart on certain event.
Upvotes: 2
Reputation: 13151
Don't know why you are confused about this, try it this way:
Move the code to a third function & call it after the func2 executes...
function funct1(){
//some other codes
button.onclick=function(){funct2(this.value)};
function func3() {
//CODES TO BE EXECUTED AFTER THE FUNCT2 RESPONDS TO SOME USER CLICK
}
function funct2(){
//some codes
func3();
}
Upvotes: 2