Reputation: 17062
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
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
Reputation: 4225
Upvotes: 0