Whatever message this page gives is out now! Go check it out!
<cfset "#flavor#_availability" = "out of stock"><cfset "Product#ProdNo#" = "Widget"><cfset prodNo = 12>
<cfset myArray[prodNo] = "Widget"><cfset productClassNo = 1>
<cfset productItemNo = 9>
<cfset "myArray[#productClassNo##productItemNo#]" = "Widget"><cfset myArray[#productClassNo# & #productItemNo#] = "Widget"><cfoutput>
Product_3 Name: #ProductName["product_" & prodNo]#
<cfoutput>Function | Purpose |
Escapes any double-quotation marks in the argument and wraps the result in double-quotation marks. The DE function is particularly useful with the IIF function, to prevent the function from evaluating a string to be output. For an example of using the DE function with the IIF function, see Using the IIF function. | |
Takes one or more string expressions and dynamically evaluates their contents as expressions from left to right. (The results of an evaluation to the left can have meaning in an expression to the right.) Returns the result of evaluating the rightmost argument. For more information on this function see About the Evaluate function. | |
Evaluates a Boolean condition expression. Depending on whether this expression is True or False, dynamically evaluates one of two string expressions and returns the result of the evaluation. The IIF function is convenient for incorporating a cfif tag in line in HTML. For an example of using this function, see Using the IIF function. | |
Operates identically to the Evaluate function, except that it can calculate arbitrary precision decimal arithmetic. If one or more operands in an arithmetic expression are decimal numbers, such as 12947834.986532, and are too long to be represented exactly by a ColdFusion numeric data type, the function uses arbitrary-precision arithmetic to calculate the result, and return the result as an arbitrarily long string of numbers. For more information about this function, see PrecisionEvaluate in the CFML Reference. | |
Sets a variable identified by the first argument to the value specified by the second argument. This function is no longer required in well-formed ColdFusion pages; see SetVariable function considerations. |
<cfoutput>#DE("1" & "2")#</cfoutput><cfset myVar="27/9">
<cfoutput>
#myVar2#<br>
#myVar#<br>
#Evaluate("myVar2")#<br>
#Evaluate("myVar")#<br>
#Evaluate(myVar2)#<br>
#Evaluate(myVar)#<br>
</cfoutput>Code | Description |
myVar2="myVar"><cfset myVar="27/9"> | Sets the two variables to the following strings:myVar27/9 |
<cfoutput>#myVar2#<br/>#myVar#<br/> | Displays the values assigned to the variables, myVar and 27/9, respectively. |
#Evaluate("myVar2")#<br> | Passes the string "myvar2" (without the quotation marks) to the Evaluate function, which does the following:1-Evaluates it as the variable myVar2. 2-Returns the value of the myVar2 variable, the string "myvar" (without the quotation marks). |
#Evaluate("myVar")#<br> | Passes the string "myvar" (without the quotation marks) to the Evaluate function, which does the following:1- Evaluates it as the variable myVar. 2-Returns the value of the myVar variable, the string "27/9" (without the quotation marks). |
#Evaluate(myVar2)#<br> | Evaluates the variable myVar2 as the string "myVar" and passes the string (without the quotation marks) to the Evaluate function. The rest of the processing is the same as in the previous line. |
#Evaluate(myVar)#<br/></cfoutput> | Evaluates the variable myVar as the string "27/9" (without the quotation marks), and passes it to the Evaluate function, which does the following:1- Evaluates the string as the expression 27/9.2-Performs the division.3-Returns the resulting value, 3 |
<cfoutput>1 + 1 is #Evaluate(1 + 1)#</cfoutput><cfoutput>1 + 1 is #Result#</cfoutput>Product Name: #Evaluate("Form.product_#i#")#
</cfoutput><cfset "myVar#i#" = myVal><cfset myVar12 = myVal><cfset result = Evaluate(argument1)>
<cfelse>
<cfset result = Evaluate(argument2)>
</cfif>#IIf(IsDefined("LocalVar"), "LocalVar", DE("The variable is not defined."))#
</cfoutput><table border="1" cellpadding="3">
<cfloop index="i" from="1" to="10">
<tr bgcolor="#IIF( i mod 2 eq 0, DE("white"), DE("gray") )#">
<td>
hello #i#
</td>
</tr>
</cfloop>
</table>
</cfoutput><table border="1" cellpadding="3">
<cfloop index="i" from="1" to="10">
<cfif i mod 2 EQ 0>
<cfset Color = "white">
<cfelse>
<cfset Color = "gray">
</cfif>
<tr bgcolor="#color#">
<td>
hello #i#
</td>
</tr>
</cfloop>
</table>
</cfoutput><head>
<title>Shopping Cart</title>
</head>
<cfscript>
CartItems=4;
Cart = ArrayNew(1);
for ( i=1; i LE cartItems; i=i+1)
{
Cart[i]=StructNew();
Cart[i].ID=i;
Cart[i].Name="Product " & i;
Cart[i].SKU=i*100+(2*i*10)+(3*i);
Cart[i].Qty=3*i-2;
}
</cfscript>
<body>
Your shopping cart has the following items.<br>
You can change your order quantities.<br>
If you don't want any item, clear the item's check box.<br>
When you are ready to order, click submit.<br>
<br>
<cfform name="ShoppingCart" action="ShoppingCartAction.cfm" method="post">
<table>
<tr>
<td>Order?</td>
<td>Product</td>
<td>Code</td>
<td>Quantity</td>
</tr>
<cfloop index="i" from="1" to="#cartItems#">
<tr>
<cfset productName= "product_" & Cart[i].ID>
<cfset skuName= "sku_" & Cart[i].ID>
<cfset qtyname= "qty_" & Cart[i].ID>
<td><cfinput type="checkbox" name="itemID" value="#Cart[i].ID#" checked>
</td>
<td><cfinput type="text" name="#productName#" value="#Cart[i].Name#"
passThrough = "readonly = 'True'"></td>
<td><cfinput type="text" name="#skuName#" value="#Cart[i].SKU#"
passThrough = "readonly = 'True'"></td>
<td><cfinput type="text" name="#qtyName#" value="#Cart[i].Qty#">
</td>
</tr>
</cfloop>
</table>
<input type="submit" name="submit" value="submit">
</cfform>
</body>
</html>Code | Description |
Cart = ArrayNew(1); for ( i=1; i LE cartItems; i=i+1) { Cart[i]=StructNew(); Cart[i].ID=i; Cart[i].Name="Product " & i; Cart[i].SKU=i*100+(2*i*10)+(3*i); Cart[i].Qty=3*i-2; } </cfscript> | Create a shopping cart as an array of structures, with each structure containing the cart item ID, product name, SKU number, and quantity ordered for one item in the cart. Populate the shopping cart by looping CartItems times and setting the structure variables to arbitrary values based on the loop counter. A real application would set the Name, SKU, and Quantity values on other pages. |
<tr> <td>Order?</td> <td>Product</td> <td>Code</td> <td>Quantity</td> </tr> | Start the form and its embedded table. When the user clicks the submit button, post the form data to the ShoppingCartAction.cfm page. The table formats the form neatly. The first table row contains the column headers. Each following row has the data for one cart item. |
<cfset productName= "product_" & Cart[i].ID> <cfset skuName= "sku_" & Cart[i].ID> <cfset qtyname= "qty_" & Cart[i].ID> <td><cfinput type="checkbox" name="itemID" value="#Cart[i].ID#" checked> </td> <td><cfinput type="text" name="#productName#" value="#Cart[i].Name#" passThrough = "readonly = 'True'"></td> <td><cfinput type="text" name="#skuName#" value="#Cart[i].SKU#" passThrough = "readonly = 'True'"></td> <td><cfinput type="text" name="#qtyName#" value="#Cart[i].Qty#"> </td> </tr> </cfloop> </table> | Loop through the shopping cart entries to generate the cart form dynamically. For each loop, generate variables used for the form field name attributes by appending the cart item ID (Carti.ID) to a field type identifier, such as "sku_". Use a single name, "itemID", for all check boxes. This way, the itemID value posted to the action page is a list of all the check box field values. The check box field value for each item is the cart item ID.Each column in a row contains a field for a cart item structure entry. The passthrough attribute sets the product name and SKU fields to read only; note the use of single-quotation marks. (For more information on the cfinput tag passthrough attribute, see the CFML Reference.) The check boxes are selected by default. |
</cfform> | Create the Submit button and end the form. |
<head>
<title>Your Order</title>
</head>
<body>
<cfif isDefined("Form.submit")>
<cfparam name="Form.itemID" default="">
<cfoutput>
You have ordered the following items:<br>
<br>
<cfloop index="i" list="#Form.itemID#">
ProductName: #Form["product_" & i]#<br>
Product Code: #Form["sku_" & i]#<br>
Quantity: #Form["qty_" & i]#<br>
<br>
</cfloop>
</cfoutput>
</cfif>
</body>
</html>Code | Description |
<cfif isDefined("Form.submit")> | Run the CFML on this page only if it is called by submitting a form. This is not needed if the form and action pages are separate, but is required if the form and action page were one ColdFusion page. |
<cfparam name="Form.itemID" default=""> | Set the default Form.itemID to the empty string. This prevents ColdFusion from displaying an error if the user clears all check boxes before submitting the form (so no product IDs are submitted). |
You have ordered the following items:<br> <cfloop index="i" list="#Form.itemID#"> ProductName: #Form["product_" & i]#<br> Product Code: #Form["sku_" & i]#<br> Quantity: #Form["qty_" & i]#<br> <br> </cfloop> </cfoutput> </cfif> | Display the name, SKU number, and quantity for each ordered item.The form page posts Form.itemID as a list containing the value attributes of all the check boxes. These attributes contain the shopping cart item IDs for the selected cart items. Use the list values to index a loop that outputs each ordered item.Use associative array notation to access the Form scope as a structure and use expressions in the array indexes to construct the form variable names. The expressions consist of a string containing the field name's field type prefix (for example, "sku_"), concatenated with the variable i, which contains the shopping cart ItemID number (which is also the loop index variable). |