Used only inside the cfswitch
tag body. Contains code to execute when the expression specified in the cfswitch
tag does not match a of the value specified by a cfcase
tag.
<cfdefaultcase>
cfcase, cfswitch; cfswitch, cfcase, and cfdefaultcase in Elements of CFML in ColdFusion MX Developer's Guide
ColdFusion MX: Changed placement requirements: this tag does not have to follow all cfcase
tags in the cfswitch
tag body.
The contents of the cfdefaultcase
tag body is executes if the expression
attribute of the cfswitch
tag does not match any of the values specified by the cfcase
tags in the cfswitch
tag body. The contents of the cfdefaultcase
tag body can include HTML and text, and CFML tags, functions, variables, and expressions.
You can specify only one cfdefaultcase
tag within a cfswitch
tag. You can put the cfdefaultcase
tag at any position within a cfswitch
statement; it is not required to be the last item, but it is good programming practice to put it last.
<!--- The following example displays a grade based on a 1-10 score. Several of the cfcase tags match more than one score. For simplicity, the example sets the score to 7. ---> <cfset score="7"> <cfswitch expression="#score#"> <cfcase value="10"> <cfset grade="A"> </cfcase> <cfcase value="9;8" delimiters=";"> <cfset grade="B"> </cfcase> <cfcase value="7;6" delimiters=";"> <cfset grade="C"> </cfcase> <cfcase value="5;4;" delimiters=";"> <cfset grade="D"> </cfcase> <cfdefaultcase> <cfset grade="F"> </cfdefaultcase> </cfswitch> <cfoutput> Your grade is #grade# </cfoutput>