I have a simple YUI dialog with 2 buttons - Accept and Decline. I would like to call ColdFusion code together with JavaScript code when each of the buttons is clicked. When I introduce CF code together with JS code unfortunately both CF code present in each of the functions get triggered.
All the code is shown below:
<script type="text/javascript">
function displayForm() {
YAHOO.namespace("example.container");
if (!YAHOO.example.container.Form) {
YAHOO.example.container.Form = new
YAHOO.widget.SimpleDialog("Form", {
modal: true,
icon: YAHOO.widget.SimpleDialog.ICON_WARN,
visible: false,
fixedcenter: true,
constraintoviewport: true,
width: "500px",
role: "alertdialog",
draggable: false,
buttons: [ { text:"Accept", handler:handleAccept, isDefault:true }, { text:"Decline", handler:handleDecline} ]
});
YAHOO.example.container.Form.setHeader("Info");
YAHOO.example.container.Form.setBody("Body");
YAHOO.example.container.Form.render(document.body);
}
YAHOO.example.container.Form.show();
}
function handleAccept() {
this.cancel();
<CFQUERY name="UpdTable" datasource="test>
UPDATE t
set a = '1'
where b = '1'
</CFQUERY>
}
function handleDecline() {
this.cancel();
<CFQUERY name="UpdTable" datasource="test>
UPDATE t
set a = '2'
where b = '1'
</CFQUERY>
}
displayForm();
</script>
The problem is that when handleAccept() is triggered automatically the handleDecline() CF code is getting triggered so I am ending up with a = '2' in the database rather than a = '1'.
Is there a workaround or a simple solution to this? Ideally, I do not want to use JS redirection.