I am trying to return results based on jQuery dialog selection. I kept alert msg before sending return statement. How to hold results to return until I do something in dialog box? value will be 'true' or 'false'
function ConfirmDone() {
var results;
$('<div></div>').appendTo('body')
.html('<div><h6>Are you sure you want to lose unsaved changes?</h6></div>')
.dialog({
modal: true, title: 'Delete message', zIndex: 10000, autoOpen: true,
width: 'auto', resizable: false,
buttons: {
Yes: function () {
$(this).dialog("close");
results=true;
},
No: function () {
$(this).dialog("close");
results=false;
}
},
close: function (event, ui) {
$(this).remove();
results = false;
}
});
alert(results); //This is calling same when dialog shows up
return results;
}
Whats wrong here?
update:
I am not sure. call back function can apply to my code? As @Barmar mentioned in duplicate post
update
@Ajax.ActionLink(
new { CommunicationLocation = commemail.Location, CommunicationType = "email" },
new AjaxOptions()
{
HttpMethod = "Post",
UpdateTargetId = "DivEmailContainer",
InsertionMode = InsertionMode.Replace,
OnBegin = "return ConfirmDone(function(success) {alert('You said: ' + (success ? 'Yes' : 'No'))});"
},
new { @class = "linkbutton" })
}
$(document).ready(function () {
$("#deletedialog").dialog({
autoOpen: false,
modal: true
});
});
function ConfirmDone(callback) {
$("#deletedialog").dialog({
buttons: {
"Delete":{ text: "Delete",
class: "btn btn-success",
click: function () {
$(this).dialog("close");
callback(true);
}
},
"Cancel": {
text: "Cancel",
class: "linkbutton",
click: function () {
$(this).dialog("close");
callback(false);
}
}
}
});
$("#deletedialog").dialog("open");