User Guide

254 Chapter 13 Extending ColdFusion Pages with CFML Scripting
Return DollarFormat(totalInterest);
}
</cfscript>
You could use the TotalInterest function in a cfoutput tag of a forms action page as
follows:
<cfoutput>
Loan amount: #Form.Principal#<br>
Annual percentage rate: #Form.AnnualPercent#<br>
Loan duration: #Form.Months# months<br>
TOTAL INTEREST: #TotalInterest(Form.Principal, Form.AnnualPercent,
Form.Months)#<br>
</cfoutput>
Example 2 This function shows the use of optional arguments. It takes two or more arguments
and adds them together.
<cfscript>
function Sum2(a,b)
{
var sum = a + b;
var arg_count = ArrayLen(Arguments);
var opt_arg = 3;
for( ; opt_arg LTE arg_count; opt_arg = opt_arg + 1 )
{
sum = sum + Arguments[opt_arg];
}
return sum;
}
</cfscript>
Using custom functions effectively
These notes provide information that will help you use custom functions more
effectively.
Using Application.cfm
Consider putting custom functions that you use frequently on the Application.cfm
page.
Queries as function parameters
When you call a custom function in the body of a tag that has a query attribute, such
as
cfloop query=... tag, a query column name parameter is normally passed as a
single element of the column, not the entire column. Therefore, functions that
manipulate query data and are called within the bodies of ColdFusion tags with
query attributes should only manipulate one query row.