Varada
Varada

Reputation: 17062

Confirmation with save and discard button

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?

Upvotes: 3

Views: 2316

Answers (3)

Breno Mansur Rabelo
Breno Mansur Rabelo

Reputation: 153

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"); 
        } 
    }
  });
}

Upvotes: 4

gaRex
gaRex

Reputation: 4225

  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!!!

Upvotes: 0

Sascha Galley
Sascha Galley

Reputation: 16091

this is not possible

more answers

Upvotes: 0

Related Questions