function Globally() {
$("#dialogid").dialog({ width: 300, modal: true, show: 'drop', hide: 'drop',
buttons: {
"Ok": function () { return true; $(this).dialog('close'); },
"Cancel": function () { return false; $(this).dialog('close'); }
}
});
}
function test()
{
if(Globally())
alert("Ok");
else
alert("Cancel");
}
I am trying to make a confirmation dialog and I want it to placed in a function (in this case Globally()) because I am using confirmation dialog in so many different function, but this is not working , the control returns from the Globally() function without getting true or false value. I want it to stop there until user press Ok or Cancel. How can I do this?
You’ll have to use built in confirm function if you want to run code like that:
That is because only confirm when used prevent whole javascript execution and allows you to pick one answer or the other (Ok, Cancel).
Dialogs like jQuery dialog can not stop script execution so even if you use
It’ll just execute Globally() function and continue right after it – not waiting for a user answer.
If you really want to use jq dialog then add callback functions to your buttons.
And ditch if/else statement() in test function.