Below is my code:
function ConfirmYesNo(title, msg) {
var $confirm = $("#myModal");
$confirm.modal('show');
$("#myModalLabel").html(title);
$("#myModalText").html(msg);
$("#btnYes").off('click').click(function () {
$confirm.modal("hide");
return 1;
});
$("#btnNo").off('click').click(function () {
$confirm.modal("hide");
return 0;
});
}
function ValidationWarning(WarningMsg) {
var a = ConfirmYesNo(Warning", WarningMsg);
}
I want to know whether the user had pressed Yes or No button before proceeding. Using return 1
or return 0
does not work for me. Any ideas?
Below is my code:
function ConfirmYesNo(title, msg) {
var $confirm = $("#myModal");
$confirm.modal('show');
$("#myModalLabel").html(title);
$("#myModalText").html(msg);
$("#btnYes").off('click').click(function () {
$confirm.modal("hide");
return 1;
});
$("#btnNo").off('click').click(function () {
$confirm.modal("hide");
return 0;
});
}
function ValidationWarning(WarningMsg) {
var a = ConfirmYesNo(Warning", WarningMsg);
}
I want to know whether the user had pressed Yes or No button before proceeding. Using return 1
or return 0
does not work for me. Any ideas?
1 Answer
Reset to default 5Try Promise in jquery: Jquery Promise or deferred.promise()
function ConfirmYesNo(title, msg) {
var dfd = jQuery.Deferred();
var $confirm = $('#myModal');
$confirm.modal('show');
$('#myModalLabel').html(title);
$('#myModalText').html(msg);
$('#name').off('click').click(function () {
$confirm.modal('hide');
dfd.resolve(1);
return 1;
});
$('#btnNo').off('click').click(function () {
$confirm.modal('hide');
return 0;
});
return dfd.promise();
}
function ValidationWarning(WarningMsg) {
var a = ConfirmYesNo('dddd', ' WarningMsg');
a.then(function (b) {
console.log(b);
alert(b)
})
}
ValidationWarning()
<script src="https://ajax.googleapis./ajax/libs/jquery/2.1.1/jquery.min.js"></script>