JavaScript callback functions not executed











up vote
0
down vote

favorite












I just started learning about callback functions. Unfortunately I can't make this altered sample-code work.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready( function() {
$(".closebtn").click(function(){
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
alert("Erste Funktion");
callback();
}

function function2(param) {
alert("Zweite Funktion");
}
})

</script>


When I click on the button nothing happens. Can anyone help?










share|improve this question






















  • Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?
    – George
    Nov 21 at 15:29






  • 1




    You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.
    – Shilly
    Nov 21 at 15:29








  • 1




    We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).
    – T.J. Crowder
    Nov 21 at 15:29

















up vote
0
down vote

favorite












I just started learning about callback functions. Unfortunately I can't make this altered sample-code work.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready( function() {
$(".closebtn").click(function(){
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
alert("Erste Funktion");
callback();
}

function function2(param) {
alert("Zweite Funktion");
}
})

</script>


When I click on the button nothing happens. Can anyone help?










share|improve this question






















  • Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?
    – George
    Nov 21 at 15:29






  • 1




    You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.
    – Shilly
    Nov 21 at 15:29








  • 1




    We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).
    – T.J. Crowder
    Nov 21 at 15:29















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I just started learning about callback functions. Unfortunately I can't make this altered sample-code work.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready( function() {
$(".closebtn").click(function(){
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
alert("Erste Funktion");
callback();
}

function function2(param) {
alert("Zweite Funktion");
}
})

</script>


When I click on the button nothing happens. Can anyone help?










share|improve this question













I just started learning about callback functions. Unfortunately I can't make this altered sample-code work.



<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script type="text/javascript">

$(document).ready( function() {
$(".closebtn").click(function(){
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
alert("Erste Funktion");
callback();
}

function function2(param) {
alert("Zweite Funktion");
}
})

</script>


When I click on the button nothing happens. Can anyone help?







javascript callback






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 21 at 15:26









user838531

12719




12719












  • Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?
    – George
    Nov 21 at 15:29






  • 1




    You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.
    – Shilly
    Nov 21 at 15:29








  • 1




    We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).
    – T.J. Crowder
    Nov 21 at 15:29




















  • Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?
    – George
    Nov 21 at 15:29






  • 1




    You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.
    – Shilly
    Nov 21 at 15:29








  • 1




    We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).
    – T.J. Crowder
    Nov 21 at 15:29


















Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?
– George
Nov 21 at 15:29




Add a button with the class closebtn and initialising the variable, this code works. What error are you getting?
– George
Nov 21 at 15:29




1




1




You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.
– Shilly
Nov 21 at 15:29






You don't show the button so we can only guess that the button does not have the class name closebtn. Maybe you meant the id #closebtn? You should also get some errors since someVariable and someOtherVariable are undefined in the code shown.
– Shilly
Nov 21 at 15:29






1




1




We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).
– T.J. Crowder
Nov 21 at 15:29






We'd need to see a more complete example. Fundamentally, you're passing the callback into function1 correctly and calling it correctly. Please update your question with a Minimal, Complete, and Verifiable example demonstrating the problem, ideally a runnable one using Stack Snippets (the [<>] toolbar button; here's how to do one).
– T.J. Crowder
Nov 21 at 15:29














1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








share|improve this answer





















  • yes, it works, it was necessary to declare the variables. thank you!
    – user838531
    Nov 22 at 10:05











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415319%2fjavascript-callback-functions-not-executed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








share|improve this answer





















  • yes, it works, it was necessary to declare the variables. thank you!
    – user838531
    Nov 22 at 10:05















up vote
1
down vote



accepted










Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








share|improve this answer





















  • yes, it works, it was necessary to declare the variables. thank you!
    – user838531
    Nov 22 at 10:05













up vote
1
down vote



accepted







up vote
1
down vote



accepted






Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








share|improve this answer












Your example works for me. Let me know what you think:






// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>








// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>





// these need to be defined
var someVariable = 'example value';
var someOtherVariable = 'example value';

$(document).ready(function() {
$(".closebtn").click(function() {
function1(someVariable, function() {
function2(someOtherVariable);
});
});


function function1(param, callback) {
console.log("Erste Funktion");
callback();
}

function function2(param) {
console.log("Zweite Funktion");
}
})

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button class="closebtn">Close</button>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 at 15:58









Rico Kahler

4,33631932




4,33631932












  • yes, it works, it was necessary to declare the variables. thank you!
    – user838531
    Nov 22 at 10:05


















  • yes, it works, it was necessary to declare the variables. thank you!
    – user838531
    Nov 22 at 10:05
















yes, it works, it was necessary to declare the variables. thank you!
– user838531
Nov 22 at 10:05




yes, it works, it was necessary to declare the variables. thank you!
– user838531
Nov 22 at 10:05


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53415319%2fjavascript-callback-functions-not-executed%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks