Possible Duplicate:
how to create yes/no/cancel box in javascript instead of ok/cancel?
In a Confirm message box, how can I change the buttons to say "Yes" and "No" instead of "OK" and "Cancel"? Is there some way to accomplish this using jQuery/Javascript? Thanks in advance for any help.
This question is related to
javascript
jquery
There is the Jquery alert plugin
$.alerts.okButton = ' Yes ';
$.alerts.cancelButton = ' No ';
Create your own confirm box:
<div id="confirmBox">
<div class="message"></div>
<span class="yes">Yes</span>
<span class="no">No</span>
</div>
Create your own confirm()
method:
function doConfirm(msg, yesFn, noFn)
{
var confirmBox = $("#confirmBox");
confirmBox.find(".message").text(msg);
confirmBox.find(".yes,.no").unbind().click(function()
{
confirmBox.hide();
});
confirmBox.find(".yes").click(yesFn);
confirmBox.find(".no").click(noFn);
confirmBox.show();
}
Call it by your code:
doConfirm("Are you sure?", function yes()
{
form.submit();
}, function no()
{
// do nothing
});
You'll need to add CSS to style and position your confirm box appropriately.
Working demo: jsfiddle.net/Xtreu
As far as I know, it's not possible to change the content of the buttons, at least not easily. It's fairly easy to have your own custom alert box using JQuery UI though
An example using jQuery UI dialog: http://jsfiddle.net/JAAulde/qqkGA/ as well as UI's own demo: http://jqueryui.com/demos/dialog/#modal-confirmation
No, it is not possible to change the content of the buttons in the dialog displayed by the confirm
function. You can use Javascript to create a dialog that looks similar.
If you switch to the jQuery UI Dialog box, you can initialize the buttons array with the appropriate names like:
$("#id").dialog({
buttons: {
"Yes": function() {},
"No": function() {}
}
});
Source: Stackoverflow.com