Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript alert with 3 buttons

Tags:

javascript

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 >

like image 523
Brian Avatar asked Jan 13 '10 02:01

Brian


People also ask

How many buttons are in a JS alert box?

An alert box is used to inform/alert the user about an event. This type of popup box has only one button, named 'OK', and has no return value.

How do I create an alert in JavaScript?

One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.

Can I customize the alert in JavaScript?

To create a custom alert box in JavaScript, you can use the “SweetAlert library, which includes a “CDN” file to enable the “Swal. fire()” method, and “JQuery” library, which will load the JQuery library in the project, fetch various attributes of the alert box and apply different functionalities on the alert box.

What is alert () function in JavaScript?

The alert() method displays an alert box with a message and an OK button. The alert() method is used when you want information to come through to the user.


2 Answers

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 help to future generations :)

like image 68
gengns Avatar answered Sep 21 '22 09:09

gengns


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!";
  }
like image 34
hfarazm Avatar answered Sep 21 '22 09:09

hfarazm