User Guide
378 Chapter 3: ColdFusion Functions
<table cellspacing = "2" cellpadding = "2" border = "0">
<cfloop index = "LoopItem" from = "1" to = "#FormElem#">
<tr>
<cfoutput>
<th align = "left">Number #LoopItem#</th>
<td><input type = "text" name = "number#LoopItem#"></td>
</cfoutput>
</tr>
</cfloop>
</table>
<input type = "submit" name = "submit" value = "get the average">
</form>
<!--- create an array --->
<cfif IsDefined("FORM.submit")>
<cfset myNumberArray = ArrayNew(1)>
<cfset Count = 1>
<cfloop index = "ListItem" list = "#Form.Fieldnames#">
<cfif Left(ListItem,3) is "Num">
<cfset myNumberArray[Count] = Val(Evaluate("number#Count#"))>
<cfset count = IncrementValue(Count)>
</cfif>
</cfloop>
<cfif Form.Submit is "get the average">
<!--- use ArrayAvg to get the average of the two numbers --->
<p>The average of the numbers that you entered is
<cfoutput>#ArrayAvg(myNumberArray)#.</cfoutput>
<cfelse>
<cfoutput>Try again. You must enter at least two numeric values.
</cfoutput>
</cfif>
</cfif>
</body>
</html>