CFLib.org – Common Function Library Project

EvenOddColor(num, evencolor, oddcolor)

Last updated November 27, 2001

Version: 1 | Requires: ColdFusion 5 | Library: UtilityLib

 
Rated 0 time(s). Average Rating: 0

Description:
This function takes 3 arguments, num,EvenColor, and OddColor. num is the number you want to return the color for, EvenColor is the color returned if num is even, OddColor is the color returned if num is odd. This can be used to easily alternate table row or even cell colors.

Return Values:
Returns a string.

Example:

view plain print about
<CFOUTPUT>
<TABLE>
<CFLOOP FROM="1" TO="10" INDEX="x">
    <TR>
    <TD BGCOLOR="#EvenOddColor(variables.x,'##FFFFFF','##CECECE')#">#variables.x#
    </TD>
    </TR>
</CFLOOP>
</TABLE>
</CFOUTPUT>

Parameters:

Name Description Required
num The number to check for even/oddness. Yes
evencolor The color to use for even numbers. Yes
oddcolor The color to use for odd numbers. Yes

Full UDF Source:

view plain print about
<cfscript>
/**
 * Returns different colors if the number passed to it is even or odd.
 * Modified by RCamden
 * 
 * @param num      The number to check for even/oddness. 
 * @param evencolor      The color to use for even numbers. 
 * @param oddcolor      The color to use for odd numbers. 
 * @return Returns a string. 
 * @author Mark Andrachek (hallow@webmages.com) 
 * @version 1.1, November 27, 2001 
 */

function EvenOddColor(num,evencolor,oddcolor) {
    return Arguments[(num mod 2 )+ 2];
}
</cfscript>
blog comments powered by Disqus

Search CFLib.org


Latest Additions

Dave Anderson Dave Anderson added
iniToStruct
20 day(s) ago

Dave Anderson Dave Anderson added
deDupeArray
20 day(s) ago

Richard Richard added
dice
22 day(s) ago

Isaac Dealey Isaac Dealey added
getRelative
a while ago

Top Rated

Darwan Leonardo Sitepu backupDatabase
Rated 5.0, 22 time(s)

Barney Boisvert indentXml
Rated 5.0, 10 time(s)

Kevin Pepperman generateSsccAsn
Rated 5.0, 4 time(s)

Raymond Camden highlightAndCrop
Rated 5.0, 4 time(s)

Created by Raymond Camden / Design by Justin Johnson