|
To access the contents, click the chapter and section titles.
Platinum Edition Using HTML 4, XML, and Java 1.2
Looping Over a List ColdFusion lists are simply a collection of items separated by some kind of delimiter character. The default delimiter is a comma, but you can choose other delimiters as well. ColdFusion enables you to loop over the items in a list by using the <CFLOOP> tag with the LIST and INDEX attributes. LIST is set equal to the list you want to loop over. INDEX specifies the name of the holding variable that takes on the values of the individual list items as the loop progresses. As a simple example of looping over a list, consider the following example: <CFSET xfiles = Mulder,Scully,Cigarette Smoking Man,Black Oil Aliens> Who is your favorite X-Files character? <FORM ACTION=favchar.cfm METHOD=POST> <CFLOOP LIST=#xfiles# INDEX=character> <CFOUTPUT> <INPUT TYPE=RADIO NAME=favorite VALUE=#character#> #character# </CFOUTPUT> </CFLOOP> <INPUT TYPE=SUBMIT VALUE=Register my Favorite> </FORM> This code produces a set of four radio buttonsone for each XFiles character in the list. Note how the INDEX variable character is used to populate the VALUE attribute of the <INPUT> tag as well as to produce the text that appears next to the radio button.
Breaking Out of a Loop You can break out of a loop before it would ordinarily terminate by using the <CFBREAK> tag. Suppose, for example, you were using a loop to look for the first non-zero element of a list: <CFLOOP LIST=0,0,4,7,0,9,0 INDEX=value> <CFIF value IS NOT 0> <CFSET magic = value> <CFBREAK> </CFIF> </CFLOOP> The first non-zero value is <CFOUTPUT>#magic#</CFOUTPUT>. On each pass through the loop, the variable value takes on the next value of the next list item. The <CFIF> tag checks to see if the current value is non-zero. If it is, it sets magic equal to that value and then breaks out of the loop because there is no point in continuing the search. Thus, the loop will stop after its third iteration (when it encounters the value of 4) rather than looping through all seven values.
Sending an Email MessageWhen you read about the ColdFusion Administrator, you learned that ColdFusion can interface with an electronic mail server to send email messages. But all you could do through the Administrator was to tell ColdFusion which mail server to use. When it comes time to actually compose and send a message, you need to use the <CFMAIL> tag. <CFMAIL> is a container tag, which means that there is a companion </CFMAIL> closing tag. You place the contents of the message you want to send between these two tags, as follows: <CFMAIL> ... message to send ... </CFMAIL> The message doesnt have to be plain text. In fact, it often includes ColdFusion variables. As long as the variable names are enclosed in pound signs, ColdFusion will replace the variable name with its value as it composes the message. Certainly more components are part of an email than the body of the message, and ColdFusion enables you to handle these other message components through attributes of the <CFMAIL> tag. Following is a complete list of the <CFMAIL> tags attributes:
|
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |