Syntax
<cfmessagebox
bodyStyle = "CSS style specification"
buttonType "yesno|yesnocancel"
callbackHandler = "function name"
icon = "error|info|question|warning"
labelCancel = "Cancel button label text"
labelNo = "No button label text"
labelOk = "OK button label text"
labelYes= "Yes button label text"
message = "message text"
modal = "yes|no"
multiline = "false|true"
name = "control name"
title = "title"
type = "alert|confirm|prompt"
width = "number of pixels"
x = "numeic pixel coordinate"
y = "numeic pixel coordinate"/>
Usage
The cfmessagebox creates
a message box, but does not show it. You show a message box, say
named mymessagebox, in JavaScript code as follows:
ColdFusion.MessageBox.show("mymessagebox");
If
you specify a callbackhandler, clicking a button in the message
box invokes the callbackhandler by passing the button label as a
parameter. For prompt boxes, an additional parameter containing
the prompt text is also passed.
For alert and confirm boxes:
var function_name = function(button);
For
prompt boxes:
var function_name = function(button, promptmessage);
The
EventObject parameter is the JavaScript ID (not the name) of the
button that was pressed.
The textmessage parameter is a string
with the contents of the prompt text box.
Example
The
following example has three buttons, one to display each type of
message box. The message box labels are customized, and the messagebox
callback function displays the type of the clicked button.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript">
//Function to to show result of a message box.
var showResult1 = function(btn,message){
alert("You entered: "+message);
}
//Function to show results of other message boxes.
var showResult2 = function(btn){
alert("You clicked button: "+btn);
}
//The button onClick handler displays the message boxes.
function showMB(mbox) {
ColdFusion.MessageBox.show(mbox);
}
</script>
</head>
<body>
<cfform>
<p>Click a button display the corresponding message box.</p>
<cfinput name="Prompt" type="button" value="Prompt"
onclick="showMB('mymessagebox01')">
<cfinput name="Prompt" type="button" value="Prompt"
onclick="showMB('mymessagebox02')">
<cfinput name="Prompt" type="button" value="Prompt"
onclick="showMB('mymessagebox03')">
</cfform>
<!--- Code to define the message boxes. --->
<cfmessagebox name="mymessagebox01" type="prompt"
message="Write a short description about yourself"
labelOK="This is OK" labelCANCEL="Cancel this"
callbackhandler="showResult1" multiline="true"/>
<cfmessagebox name="mymessagebox02" type="confirm"
message="Is it OK to save the planet?"
labelNO="Dont Save" labelYES="Sure"
callbackhandler="showResult2"/>
<cfmessagebox name="mymessagebox03" type="alert"
message="You have been ALERTED!"
callbackhandler="showResult2" />
</body>
</html>