I am facing some issues with the alert window being displayed. What I want is to display alert window and then based upon user's input I need to perform some action. But the problem I am facing is that I receive null as return value from the function.
PS: I am using Jquery msgbox v1.0 for alerts.
Here is the calling function code block -
var retVal = "No"; //don't save
if($(this).parent().parent().hasClass("modified")){
retVal = showPrompt();//Null returned
}
alert(retVal);
switch (retVal) {
case "Yes":
//show download xml file on machine.
removeWorkspace(this);
break;
case "No":
removeWorkspace(this);
break;
case "Cancel":
//don't do anything
break;
}
event.stopPropagation();
});
Called Function:
function showPrompt(){
var resultVar = null;
$.msgBox({
title: "Are you sure",
content: "Do you want to save your work?",
type: "confirm",
buttons: [{ type:"submit", value: "Yes"},
{type: "submit", value: "No"},
{type: "cancel", value: "Cancel"}]
}, function(result){
resultVar = result;
});
return resultVar;
}
Thanks in advance.
msgBox
does not behave asalert
orconfirm
: when called, it does not suspend the current execution thread.Your function returns before the user has clicked on any button.
The simplest way to fix this would be to call your
removeWorkspace
function from the "success" callback :