6

How to create a yes/no/cancel alert box instead of ok/cancel alert box in Javascript?

3 Answers3

9

You can't.

Instead, you can use a fake dialog library, such as jQuery UI Dialog.

These libraries create HTML elements that look and behave like a dialog box, allowing you to put anything you want (including form elements or video) in the dialog.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
  • I use jQueryUI quite a lot myself-- but I would simply like to mention there are a vast and open sea of already created libraries for use. Google for Javascript UI, custom javascript dialog, things like that... You will find some cool stuff. I'd like to say you don't need to bother writing your own code for them, but you might want to anyway. – Incognito Jun 24 '10 at 14:38
0

There's nothing native built in to do this. You could use a framework to simulate it, for example: http://www.sencha.com/deploy/dev/docs/?class=Ext.MessageBox

Evan Trimboli
  • 29,900
  • 6
  • 45
  • 66
-1

This will work in IE, but as for other browsers I'm not sure. It's important to note that yes/no/cancel is not officially supported by Javascript so you are better off using ok/cancel wherever possible.

<script language=javascript>

/*@cc_on @*/
/*@if (@_win32 && @_jscript_version>=5)

function window.confirm(str)
{
    execScript('n = msgbox("'+str+'","4132")', "vbscript");
    return(n == 6);
}

@end @*/
var r = confirm("Can you do it?");
alert(r);
</script>
Tom Gullen
  • 61,249
  • 84
  • 283
  • 456