Description

Defines a control for displaying pop-up messages. The control has more features than the standard alert box, including the ability to include a prompt and entry field in the box.

Category

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"/>

History

ColdFusion 9: Added this tag

Attributes

Attribute

Req/Opt

Default

Description

bodyStyle

Optional

 

A CSS style specification for the body of the message box. As a general rule, use this attribute to set color and font styles.

buttonType

Optional

yesno

Applies to the control type - confirm.
The buttons to display on the message box:

  • yesno: displays the buttons Yes and No
  • yesnocancel: displays the buttons Yes, No, and Cancel

callbackhandler

Optional

 

The function that the control calls when a user clicks one of the buttons. For more information see Usage.

icon

Optional

 

Specifies the following CSS classes:

  • error: Provides the error icon. You can use this icon when displaying error messages.
  • info: Provides the info icon. You can use this icon when displaying any information.
  • question: Provides the question icon. You can use this icon in a confirmation message box that prompts a user response.
  • warning: Provides the warning icon. You can use this icon when displaying a warning message.

labelCancel

Optional

Cancel

The text to put on the cancel button of a prompt message box.

labelOk

Optional

OK

The text to put on an alert button and prompt message box OK button.

labelNo

Optional

No

The text to put on the button used for a negative response in a confirm message box.

labelYes

Optional

Yes

The text to put on the button used for a positive response in a confirm message box.

message

Optional

 

The text to display inside the message box.

modal

Optional

yes

A Boolean value that specifies if the message box must be a modal window:

  • yes
  • no

multiline

Optional

false

Valid only for prompt type message boxes. A boolean value specifying whether the prompt input text box has a single or multiple lines for text input.

name

Required

 

The control name. Used to refer to the control in JavaScript.

title

Optional

 

The title for the message box.
If you do not specify a title, ColdFusion assigns the control type value as the default title.

type

Required

 

The control type. Must be one of the following:

  • alert - A message with a single OK button.
  • confirm - A message box with two buttons YES and NO or three buttons YES, NO, and CANCEL.
  • prompt - a message box with a single-line or multiline text input area and OK and CANCEL buttons.

width

Optional

 

Width of the message box in pixels.

x

Optional

 

The X (horizontal) coordinate of the upper-left corner of the message box.ColdFusion ignores this attribute if you do not set the y attribute.

y

Optional

 

The Y (vertical) coordinate of the upper-left corner of the message box.ColdFusion ignores this attribute if you do not set the x attribute.

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>

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy