Reputation: 888
I have to show Confirmation message buttons as "Yes" or "No", for that i am showing jquery dialog box as
function ConfirmDialog(message) {
$('<div></div>').appendTo('body')
.html('<div><h6>' + message + '?</h6></div>')
.dialog({
modal: true,
title: 'Message',
zIndex: 10000,
autoOpen: true,
width: 'auto',
resizable: false,
buttons: {
Yes: function (e) {
$(this).dialog("close");
return true;
},
No: function () {
$(this).dialog("close");
return false;
}
},
close: function (event, ui) {
$(this).remove();
}
});
};
But my requirement is when i click "Yes" it should return as true like
var msg = ConfirmDialog("Are You Sure , Do you want to Delete all items??");
if (msg == true) {
alert("you clicked yes");
} else {
alert("you clicked No");
}
For that , i have return as true, but script is not working like, and one more is I can't write script in "Yes" button function, due to some issues, please help me anyone.
Upvotes: 0
Views: 182
Reputation: 309
What you want is a confirm() like functionality which is directly browser supported and custom implementation of it is not possible. What you really have to do is put your code in click event of 'yes' and 'no' button.
$('#btnYes').click(function(){
alert("you clicked yes");
});
$('#btnNo').click(function(){
alert("you clicked No");
});
Upvotes: 0
Reputation: 337560
You can't 'return' anything from a dialog box. Instead you should have a function which you run based on the button clicked in the dialog, something like this:
.dialog({
// other settings...
buttons: {
Yes: function (e) {
$(this).dialog("close");
dialogResult(true);
},
No: function () {
$(this).dialog("close");
dialogResult(false);
}
},
});
Upvotes: 4