15

I have a JavaScript alert button that appears on the website when a user is going to proceed to a signup page.

It looks something like this

Would you like to proceed to the signup page?
< OK > < Cancel >

Would it be possible to add a third button to the alert so that it looks like

Would you like to proceed to the signup page?
< More Info > < OK > < Cancel >

Brian
  • 26,662
  • 52
  • 135
  • 170

4 Answers4

16

No.

You need to use a custom modal dialog, such as jQuery UI Dialog.

SLaks
  • 868,454
  • 176
  • 1,908
  • 1,964
5

Nowdays, you can use an HTML dialog element.

<dialog open>
  <p>Greetings, one and all!</p>
  <button>Ok</button><button>Maybe</button><button>Cancel</button>
</dialog>

And do what you want with it.

document.querySelectorAll('button').forEach($button => 
  $button.onclick = () => document.querySelector('dialog').removeAttribute('open'))

https://jsfiddle.net/6nus2zt4/1/

Hope this helps to future generations :)

gengns
  • 1,573
  • 14
  • 23
4

however you can use confirm function.. but NOT three buttons.

var r=confirm("Press a button!");
if (r==true)
  {
  x="You pressed OK!";
  }
 else
  {
  x="You pressed Cancel!";
  }
hfarazm
  • 1,407
  • 17
  • 22
3

Unfortunately, I don't think you can change the number of buttons in an alert box. (At least not in any browser that I know of.) You can use one of the many modal dialog scripts that are out on the net. Something like Eric Martin's SimpleModal Dialog for jquery would probably work.

They basically take a div and style it up with css and javascript to mimic a dialog box.

Community
  • 1
  • 1
mwgriffith
  • 550
  • 3
  • 6