I'm developing a javascript class (with jQuery) to create custom popup, but I can not figure out how to "pause" the script to wait for user response (click on the OK button or cancel)
the class is like this:
function Popup()
{
}
Popup.Show = function(text)
{
var _response;
/* code to draw the popup elements*/
$("#button-ok").on("click",function()
{
_response = "ok!"
}
return _response
}
if, for example, use it in an alert, the method always return "undefined", because it does not wait for user click
alert(Popup.Show("hello"))
//return undefined before the popup appears
I tried to use a while loop like this:
Popup.Show = function(text)
{
var _response;
var _wait = true;
/* code to draw the window */
$("#button-ok").on("click",function()
{
_wait = false;
_response = "ok!"
}
while(_wait){};
return _response
}
but does not work (as I expected)
Then, how do I wait for the user click?
Thanks to all