Skip to content Skip to sidebar Skip to footer

Display Yes And No Buttons Instead Of Ok And Cancel In Confirm Box?

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 '

Solution 1:

Create your own confirm box:

<divid="confirmBox"><divclass="message"></div><spanclass="yes">Yes</span><spanclass="no">No</span></div>

Create your own confirm() method:

functiondoConfirm(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

Solution 2:

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() {}
  }
});

Solution 3:

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

Solution 4:

There is the Jquery alert plugin

$.alerts.okButton = ' Yes ';
$.alerts.cancelButton = ' No ';

Solution 5:

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

Post a Comment for "Display Yes And No Buttons Instead Of Ok And Cancel In Confirm Box?"