jQuery Confirmation on Class
Code to assign a jquery dialog to the .confirmClick class on any element.
$(".confirmClick").live("click", function(event) {
    // Stop the default action from occuring.
    var clickedButton=$(this);
    event.preventDefault();
    var targetUrl = $(this).attr("href");

    // Set up the error message,
    if ($(this).attr('title')) {
        var question = 'Are you sure you want to ' + $(this).attr('title').toLowerCase() + '?';
    } else {
        var question = 'Are you sure you want to do this?';
    }
    //  copy it to a hidden element.
    $("#dialogmsg").html(question);

    
    // Initiate the dialog box
    $("#dialog").dialog({
        bgiframe: false,
        resizable: false,
        height:140,
        modal: true,
        overlay: {
            backgroundColor: '#000',
            opacity: 0.5
        },
        buttons: {
            OK: function() {
                $(this).dialog('destroy');
                // Set behavior based on link or form.
                if (targetUrl){
                    window.location.href = targetUrl;
                }else{
                    //$(clickedButton).attr("name").submit();
                    $(clickedButton).closest("form").submit();
                }        

            },
            Cancel: function() {
                $(this).dialog('close');
                $(this).dialog('destroy');
                return 1
            }
        }
    });

});

 

Add comment

Security code
Refresh