montrealmike montrealmike - 1 month ago 15
Javascript Question

Javascript modal to replace prompt?

What is the best way to replace

var value = prompt("Enter a URL", "http://www.google.com/");


by a javascript modal (preferably pure javascript, if not possible then jquery)

Thanks!

Answer

You will need to change theway you call it, so it now follows event-driven programming style like that:

function prompt(question, callback) {
    // here build a modal/form and after form submit:
    callback(prompt_value);
}

And then use it like that:

prompt('Enter a URL:', function(result){
    // do something with the result:
    alert(result);
});
Comments