Reputation: 47
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");
}
}
Upvotes: 0
Views: 380
Reputation: 2536
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/
Upvotes: 1
Reputation: 28722
use this:
<button value="click me" onclick="fnOpenNormalDialog()">
You need to add the brackets for the function call to succeed.
Upvotes: 0