'How to activate callback on modal confirmation?

I need some very basic help. Basically, im trying to create a Modal Confirmation dialog, and i've got most of it down. Simply put, it's a dialog asking "Are you sure?" with two buttons "Yes" and "No"

<script>
$(function() {
    $( "#dialog-confirm" ).dialog({
        resizable: false,
        height:140,
        modal: true,
        buttons: {
            "Yes": function() {},
            "No": function() {
                $( this ).dialog( "close" );
            }
        }
    });
});
</script>

What do i so that when "yes" is hit, the box closes and finished running the script i want? It maybe a newb thing, but i'm learning as i go, and not in any particular order

Update 1

New code:

$('#stats_ensaves').click(function(){
        $('#thedialog').dialog('open');
        return false;
    });
    $('#thedialog').dialog({
        autoOpen: false,
        width: 300,
        buttons: {

            "Confirm": function(){
                $("#stats_ensaves").dialog("open");

            },

            "Cancel": function() {
                $(this).dialog("close");

            }
        }
    });

stats_ensaves is right here: <span class="playerstat">Energy Saves: </span> <span id="stats_ensaves"><a href="http://www.galatium.net/account.php?onnow=N" id="link"><b>ON</b> (7 left)</a></span>

My new question is: Why isn't the confirm button linking me to that link?



Solution 1:[1]

What script do you want to run? It's not shown nor referenced. I'll assume it's called myFunction.

here is a fiddle

Note: please tag these as jquery-ui

Solution 2:[2]

...
        buttons: {
            "Yes": function() {
                // some code here when yes was clicked
                $( this ).dialog( "close" );
             },
            "No": function() {
                $( this ).dialog( "close" );
            }
...

Solution 3:[3]

$(".confirm").click(function(e) {
    e.preventDefault();
    var targetUrl = $(this).attr("href");
    var $dialog-confirm = $('<div></div>').
        html("<p>Are you sure?</p>").
        dialog({autoOpen: false,
        title: 'Please Confirm',
        buttons : {
            "Yes" : function() {....},
            "No" : function() {....}
        },
        modal: true
    });

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 gillyspy
Solution 2 HMR
Solution 3 catherine