Question

I have found a dialog box script http://jsfiddle.net/taditdash/vvjj8/ which I want to work with button onclick. But it's not working. Any Help?

My modification

<input type="button" id="btnOpenDialog" value="Open Confirm Dialog"    onclick="fnOpenNormalDialog()"/>
<div id="dialog-confirm"></div>

function fnOpenNormalDialog() {
    $("#dialog-confirm").html("Confirm Dialog Box");

    // Define the Dialog and its properties.
    $("#dialog-confirm").dialog({
        resizable: false,
        modal: true,
        title: "Modal",
        height: 250,
        width: 400,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                callback(true);
            },
                "No": function () {
                $(this).dialog('close');
                callback(false);
            }
        }
    });
}

function callback(value) {
    if (value) {
        alert("Confirmed");
    } else {
        alert("Rejected");
    }
}
Was it helpful?

Solution

Just enclose your javascript functions in tags to HTML block like this :

<input type="button" id="btnOpenDialog" value="Open Confirm Dialog"    onclick="fnOpenNormalDialog()"/>
<div id="dialog-confirm"></div>
<script>
    function fnOpenNormalDialog() {
    $("#dialog-confirm").html("Confirm Dialog Box");
    // Define the Dialog and its properties.
    $("#dialog-confirm").dialog({
        resizable: false,
        modal: true,
        title: "Modal",
        height: 250,
        width: 400,
        buttons: {
            "Yes": function () {
                $(this).dialog('close');
                callback(true);
            },
                "No": function () {
                $(this).dialog('close');
                callback(false);
            }
        }
    });
}
function callback(value) {
    if (value) {
        alert("Confirmed");
    } else {
        alert("Rejected");
    }
}
</script>

DEMO : http://jsfiddle.net/vvjj8/106/

OTHER TIPS

use this:

<button value="click me" onclick="fnOpenNormalDialog()">

You need to add the brackets for the function call to succeed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top