Confirmation Dialog with jQuery

A confirmation dialog asks the user to approve or cancel an action before it continues. This example uses jQuery UI Dialog and passes the result to a callback.

No choice yet.

Create the Dialog Top ↑

$( "#confirm-dialog" ).dialog({
    autoOpen: false,
    modal: true,
    resizable: false,
    width: 400,

    buttons: {
        Yes: function () {
            $( this ).dialog( "close" );
            handleConfirmation( true );
        },

        No: function () {
            $( this ).dialog( "close" );
            handleConfirmation( false );
        }
    }
});

Handle the User Choice Top ↑

function handleConfirmation( confirmed ) {
    $( "#confirm-result" ).text(
        confirmed
            ? "You clicked Yes."
            : "You clicked No."
    );
}

Open the Dialog Top ↑

$( "#confirm-open" ).on( "click", function () {
    $( "#confirm-message" ).text(
        "Confirm to submit?"
    );

    $( "#confirm-dialog" ).dialog( "open" );
});

Original confirmation-box demo →

jQuery UI Dialog tutorial · click events

Original Source Examples Retained for Migration Reference Top ↑

These source-page examples are preserved so no learner-purpose code is silently lost. Use the modern examples above as the recommended implementation.

Original example 1

$("#dialog-window").dialog({
        resizable: false,
        autoOpen: false,
        modal: true,
        title: "Confirm Box",
        height: 250,
        width: 400,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                callback(true);
            },
                "No": function () {
                $(this).dialog('close');
                callback(false);
            }
        }
 });

Original example 2

function callback(value) {
 if (value) {
  $('#display').html('You clicked Yes button') 
 }// end of if (value )
else{
// code to execute if false
$('#display').html('You clicked No button') 
}
} // end of callback function

Original example 3

$("#b1").click(function(){
$("#dialog-window").html("Confirm to Submit ...");
$( "#dialog-window" ).dialog( "open" );
})

Additional Original Learning Routes Top ↑






plus2net.com






✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer