JCDesigns
asked on
Coldfusion CFMESSAGEBOX Passing Variables
What im trying to do is simple, im sure.. Im just a bit rusty when it comes to these things..
Essentially all im trying to do is have a Confirm Delete Message Box popup when a button is pressed next to all my DB rows listed on the page -- then after "Confirm" is pressed it proceeds to reload the page and process the record delete
and heres the call button code:
My problem is that the CF Box is not passing over the #ID# variable when it reloads the page.
another issue i just noticed is that it processes the fucntion regardless of which option you choose! Confirm = Run script and Cancel = also runs same script instead of just cancelling the message box.
Essentially all im trying to do is have a Confirm Delete Message Box popup when a button is pressed next to all my DB rows listed on the page -- then after "Confirm" is pressed it proceeds to reload the page and process the record delete
<head>
<script type="text/javascript">
var confirmDel = function(btn){
ColdFusion.navigate("ADMIN_LIST_DELETE.cfm?Delete=true&ID=#ID#");
}
</script>
</head>
and heres the call button code:
<cfform action="ADMIN_LIST_DELETE.cfm?Delete=true&ID=#ID#" method="post" name="DelListing">
<cfinput name="Prompt" type="button" value="DELETE LISTING" onclick="showMB('confimdelete')">
<cfmessagebox name="confimdelete" type="confirm" message="Are you sure you wish to Delete this Listing?"
labelNO="CANCEL" labelYES="CONFIRM DELETE" callbackhandler="confirmDel" icon="warning"/>
</cfform>
My problem is that the CF Box is not passing over the #ID# variable when it reloads the page.
another issue i just noticed is that it processes the fucntion regardless of which option you choose! Confirm = Run script and Cancel = also runs same script instead of just cancelling the message box.
ASKER
Thanks. I understand what you've done there. That should do the trick. I'll give it a try once I'm back Infront of a computer.
ASKER
Sorry for the delay.. but i finally got a chance to try this.. but the problem is setting that initial #ID# value.
In your example, you simply cfset it to 10, but on my page i have every record being displayed, and each has its own ID & button. I need to pass that ID var into the URL depending on which "Delete" button was pressed.
Thats sorta where my problem lies initially.
In your example, you simply cfset it to 10, but on my page i have every record being displayed, and each has its own ID & button. I need to pass that ID var into the URL depending on which "Delete" button was pressed.
Thats sorta where my problem lies initially.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I happened have implemented similar case.
So here is fully functional code. Feel free to modify to your needs.
<cfset id=10/>
<cfset deleteLink = "cfmessageTest.cfm?Delete=
<!--- This is for test only --->
<cfif isdefined ("url.delete")>
<cfif url.delete eq true>
<h1>
<cfoutput>Now I will delete the file. and show the detailed deletetion message error</cfoutput>
</h1>
<cfdump var="#url#"/>
</cfif>
<cfexit/>
</cfif>
<html>
<head>
<script type="text/javascript">
var dbgFlag = false;
//
// Save Coldfusion value as Javascript variable
//
//
var deleteID = <cfoutput>#id#</cfoutput>;
//
// show Message Box
//
function showMB(mbox) {
ColdFusion.MessageBox.show
};
//
// Callback confirmation for Delete
//
var confirmDel = function(btn){
//
if (dbgFlag) {
alert ('You clicked on ' + btn + ' Button');
alert ("Delete Link " + <cfoutput>"#deleteLink#"</
}
//
// If yes is pressed, proceed to delete
//
if (btn.match("yes")) {
// Redirect the navigate action to CFWindow.
// This is optional, but nice to have. User does not have to leave current page
// This window can be closed.
//
ColdFusion.navigate("<cfou
//
// Now show the window.
//
ColdFusion.Window.show("Te
}
}
</script>
<style type="text/css">
* { font-size: 24px; }
</style>
</head>
<body>
<!--- CF form --->
<cfform action="#deleteLink#" method="post" name="DelListing">
<cfinput name="Prompt" type="button" value="DELETE LISTING" onclick="showMB('confimdel
<cfmessagebox name="confimdelete" type="confirm" message="Are you sure you wish to Delete this Listing?"
labelNO="CANCEL" labelYES="CONFIRM DELETE" callbackhandler="confirmDe
</cfform>
<!--- CF Windows, hidden initailly --->
<cfwindow name="TestWindow" center="true" width="800" height="600" closable="true" title="ImageView" initshow="false">Initial Text Here</cfwindow>
</body>
</html>