how to show confirmation alert with three buttons ‘Yes’ ‘No’ and ‘Cancel’ as it shows in MS Word

I’m showing a confirmation alert box through JavaScript:

function checked() {
 if (hdnval.toLowerCase() != textbox1.toLowerCase()) {
  var save = window.confirm('valid')
   if (save == true) 
     return true;
      return false;

The confirmation alert is showing with two buttons: OK and Cancel.

I want to show a third button in my confirmation alert. I want the three buttons to be like this: ‘Yes’ ‘No’ ‘Cancel’, as it shows in MS Word.


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

This cannot be done with the native javascript dialog box, but a lot of javascript libraries include more flexible dialogs. You can use something like jQuery UI’s dialog box for this.

See also these very similar questions:

Here’s an example, as demonstrated in this jsFiddle:

    <script type="text/javascript" src=""></script>
    <script type="text/javascript" src=""></script>
    <link rel="stylesheet" type="text/css" href="/css/normalize.css" rel="nofollow noreferrer noopener">
    <link rel="stylesheet" type="text/css" href="/css/result-light.css" rel="nofollow noreferrer noopener">
    <link rel="stylesheet" type="text/css" href="" rel="nofollow noreferrer noopener">
    <a class="checked" href="" rel="nofollow noreferrer noopener">Click here</a>
    <script type="text/javascript">

        $(function() {
            $('.checked').click(function(e) {
                var dialog = $('<p>Are you sure?</p>').dialog({
                    buttons: {
                        "Yes": function() {alert('you chose yes');},
                        "No":  function() {alert('you chose no');},
                        "Cancel":  function() {
                            alert('you chose cancel');


Method 2

If you don’t want to use a separate JS library to create a custom control for that, you could use two confirm dialogs to do the checks:

if (confirm("Are you sure you want to quit?") ) {
    if (confirm("Save your work before leaving?") ) {
        // code here for save then leave (Yes)
    } else {
        //code here for no save but leave (No)
} else {
    //code here for don't leave (Cancel)

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x