tags:

views:

40

answers:

2

I am sifting through prompt() and confirm() replacements for JavaScript. I need to create a couple of confirm()s and alert()s that have three or more options. I would like to use the Lightbox class that I am using already. However, none of the replacements I have found can return the result of the operation directly like confirm() and prompt() can:

success = confirm("Success yes / no?");
if (success == true)
 ......

can a replacement be written so that it behaves in the same manner, i.e. that it opens a dialog, waits for user input and returns which buttons have been clicked? Or is this impossible to do (That's what I'm suspecting right now) and you have to work around it by attaching the actions to the "yes / no / whatever" buttons themselves?

+1  A: 

Both IE and Firefox 3 have a showModalDialog method which would allow you to display an entire web page modally. However for a truely cross-browser solution you can't use that.

Many of the popular frameworks provide a mechanism to do it by displaying a HTML element and disabling access to the rest of the web page whilst the element is displayed.

AnthonyWJones
+2  A: 

Most JavaScript frameworks that have UI components have some kind of dialog that will provide callbacks. Check out jQuery UI, for example: http://jqueryui.com/demos/dialog/

I've used it in multiple projects to do exactly what you're describing.

Josh