Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 683
Varada Avatar asked Jan 23 '26 03:01

Varada


1 Answers

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"); 
        } 
    }
  });
}
like image 94
Breno Mansur Rabelo Avatar answered Jan 24 '26 18:01

Breno Mansur Rabelo