I'm using bPopup to crate modal popup windows on my website (http://dinbror.dk/bpopup/)
Now I'm trying to create a prompt window with it.. I wrote a function that would create and open a popup and destroy when closed, returning a value.. but, I can't get it to return the value.. this is my code until now:
function promptbox(title, default_value) {
$("body").append("<div id='prompt-box'><div>"+title+"</div><input type='text' value='"+default_value+"''></input><button class='close'>OK</button></div>");
$('#prompt-box').bPopup({
onClose: function(){ $("#prompt-box").remove(); return $("#prompt-box input").val();},
closeClass:"close"
});
}
When I run:
var typed_text = promptbox('What is the input?')
It gets an undefined value. I know that the promptbox function is not returning anything, but is there a way to pass the return responsibility on to the popup?
I looked into How do I return the response from an asynchronous call? but it seems that the question and solutions are more related to ajax requests. I tried to use jquery deferred objects, but even though in jquery documentation it says it can be used for anything (not only ajax) most examples are ajax related.
I'd imagine it would be a bit easier to pass a callback to the function, but I want to know if I can use it as a value returning function, so that it can be used with the line of code above.
I'm really lost on this. Any help would be appreciated.