Replace ALERTs

by Bianca Kuehweidner

HTML

<!-- 
btnDelete.Attributes.Add("onclick", "if (confirm(\'Are you sure?\')){ " +
     this.Page.ClientScript.GetPostBackEventReference(this, String.Format("{0}|{1}", "delete", User.Id.ToString())) + ";}"); 
-->

<input type="button" value="click me" onclick="if (confirm('Question','Are you sure?')) { console.log('I am'); }" />

JavaScript

window.confirm = function (title, message) {
      var returnValue = false;

      $(document.createElement('div'))
        .attr({ title: title, class: 'confirm' })
        .html(message)
        .dialog({
            buttons: {
                "OK": function () {
                    returnValue = true;
                    console.log("OK: " + returnValue);
                    $(this).dialog("close");                    
                },
                "Cancel": function () {
                    returnValue = false;
                    console.log("Cancel: " + returnValue);
                    $(this).dialog("close");                    
                }
            },
            close: function () {
                $(this).remove();
                return returnValue;
            },
            draggable: true,
            modal: true,
            resizable: false,
            width: 'auto'
        });
};