I am using bootbox for confirm alert box that I alert to user. It is called from one js file and I have a common function where it is created. How can I use callback function to get the result of the confirm dialog box:
So my js is as below:
var message = "Do you want to close?";
loadConfirmAlert(message);
if (result) {
//do stuff
}
The loadCofirmAlert function in another js file then is as below:
var loadCofirmAlert = function (message) {
bootbox.confirm(message, function (result) { });
}
what I am unsure off is how to pass this result value back to the calling function?
Try it like this
var message = "Do you want to close?";
loadConfirmAlert(message,function(result){
if (result) {
//do stuff
}
});
var loadCofirmAlert = function (message,callback) {
bootbox.confirm(message, function (result) {
callback&&callback(result);
});
}
UPDATE
Where
callback&&callback(result)
Is just a shorter version of
if (callback)callback(result); //if callback defined, call it
You can also use checking if callback is a function by using
(typeof(callback)==="function")&&callback(result)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments