3

How can we create a confirmation alert in javascript with a save and discard button in it? If we use the code

confirm('Do you want to save it?');

We will get an alert box with ok cancel. How can we make the text of ok button as save and the other as discard?

Varada
  • 16,026
  • 13
  • 48
  • 69
  • possible duplicate of [Changing the default title of confirm() in JavaScript?](http://stackoverflow.com/questions/43955/changing-the-default-title-of-confirm-in-javascript) – Quentin May 31 '11 at 11:01
  • Have a look at this similar question: http://stackoverflow.com/questions/823790/javascript-confirm-popup-yes-no-button-instead-of-ok-and-cancel – Kris May 31 '11 at 11:02

3 Answers3

4

You cannot modify the default javascript method "confirm". But, you can override it, for example, with jQuery UI dialog:

window.confirm = function (message) {
  var html = "<div style='margin:20px;'><img style='float:left;margin-right:20px;' src='/img/confirm.gif' alt='Confirm'/><div style='display:table;height:1%;'>" + message + "</div></div>";

  $(html).dialog({ closeOnEscape: false,
    open: function (event, ui) { $('.ui-dialog-titlebar-close').hide(); },
    modal: true,
    resizable: false,
    width: 400,
    title: "Confirmation",
    buttons: { 
        "Save": function () {
            //Do what you need
        },
        "Cancel": function () {
            $(this).dialog("close"); 
        } 
    }
  });
}
0

this is not possible

more answers

Community
  • 1
  • 1
Sascha Galley
  • 15,711
  • 5
  • 37
  • 51
0
  1. Connect some of the tons JS framework. For example jQuery+UI
  2. Overwrite window.confirm method, by makin it as wrapper to your favorite JS UI framework.
  3. PROFIT!!!
gaRex
  • 4,144
  • 25
  • 37