Women in Technology

Hear us Roar



Article:
  ColdFusion MX on Mac OS X, Part 3
Subject:   cfswitch / cfcase ???
Date:   2002-11-05 13:52:23
From:   adolph
Has anyone had any luck using cfswitch and cfcase? I don't think it is working on my deployment. The following code doesn't display anything but the form using cfswitch/cfcase, but it does work fine with cfif/cfelseif/cfelse....


<cfparam name="switch_value" default="1">
<cfswitch expression="switch_value">
<cfcase value="1">
<h1>Value = 1</h1>
<cfset switch_value="2">
</cfcase>
<cfcase value="2">
<h1>Value = 2</h1>
</cfcase>
</cfswitch>
<cfswitch expression="switch_value">
<cfcase value="1">
<h1>Value = 1</h1>
</cfcase>
<cfcase value="2">
<h1>Value = 2</h1>
</cfcase>
</cfswitch>
<form method="post">
<input type="text" name="switch_value" value="<cfoutput>#switch_value#</cfoutput>">
<input type="submit" name="Submit" value="Submit">
</form>

Full Threads Oldest First

Showing messages 1 through 3 of 3.

  • problem was with cfswitch syntax
    2002-11-05 14:18:07  adolph [View]

    Sorry for needlessly adding another comment line....

    I had a syntax error. If you want cfswitch to evaluate a specific variable, you should use <cfswitch expression="#variable#">, not <cfswitch expression="variable">. I was a little confused by the documentation in Programming ColdFusion, pg. 32, 33, 791.

    So the solution was:

    <cfparam name="switch_value" default="1">
    <cfswitch expression="#switch_value#">
    <cfcase value="1">
    <h1>Value = 1</h1>
    <cfset switch_value="2">
    </cfcase>
    <cfcase value="2">
    <h1>Value = 2</h1>
    </cfcase>
    </cfswitch>
    <hr>
    <cfswitch expression="#switch_value#">
    <cfcase value="1">
    <h1>Value = 1</h1>
    </cfcase>
    <cfcase value="2">
    <h1>Value = 2</h1>
    </cfcase>
    </cfswitch>
    <form method="post">
    <input type="text" name="switch_value" value="<cfoutput>#switch_value#</cfoutput>">
    <input type="submit" name="Submit" value="Submit">
    </form>
    • Works for me
      2002-11-06 10:27:55  anonymous2 [View]

      Your program works for me -- thou the logic is a little strange.

      Dick
  • It works fine with cfif...
    2002-11-05 13:55:12  adolph [View]

    using the following code:
    <cfparam name="switch_value" default="1">
    <cfif switch_value eq "1">
    <h1>1</h1>
    <cfset switch_value = "2">
    <cfelseif switch_value eq "2">
    <h1>2</h1>
    </cfif>
    <hr>
    <cfif switch_value eq "1">
    <h1>1</h1>
    <cfset switch_value = "2">
    <cfelseif switch_value eq "2">
    <h1>2</h1>
    </cfif>
    <form method="post">
    <input type="text" name="switch_value" value="<cfoutput>#switch_value#</cfoutput>">
    <input type="submit" name="Submit" value="Submit">
    </form>