MACROMEDIA COLDFUSION MX 61-DEVELOPING COLDFUSION MX Develop Manual page 100

Developing coldfusion mx applications
Table of Contents

Advertisement

<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>
Save the page as ShoppingCartForm.cfm.
2
Reviewing the code
The following table describes the code:
Code
<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>
<cfform name="ShoppingCart"
action="ShoppingCartAction.cfm"
method="post">
<table>
<tr>
<td>Order?</td>
<td>Product</td>
<td>Code</td>
<td>Quantity</td>
</tr>
100
Chapter 4: Using Expressions and Pound Signs
Description
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.
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.

Advertisement

Table of Contents
loading

This manual is also suitable for:

Coldfusion mx

Table of Contents