You cannot do this, it is impossible, for reasons not related to closing.
Without calling the code that sets int_val , you only define the code and say, "When the buttons are clicked, call that code." The code will not be executed at the time of launching return int_val , it will be executed at some point in the future when the button is clicked.
This code block cannot logically work:
// First line run var int_val = 0; // Second line run $(".button").click(function () { // This line runs in the future, or maybe never, if the button isn't clicked int_val = ($(this).val() == 'yes' ? '1' : '0'); }); // Third line run return int_val;
If you want to pass values ​​back from asynchronous functions, you should use promises:
function popup_modal() { var dfd = $.Deferred(); $(".button").click(function () { int_val = ($(this).val() == 'yes' ? '1' : '0');
The calling code will receive a promise object that can add callbacks:
function popup_confirme() { var r; popup_modal().done(function (int_val) { r = int_val; } }
I cannot understand what you meant int_val to execute the call code.
source share