Skip to main content
Inspiring
November 15, 2012
Question

Adding a CFCASE to a Coldfusion SELECT dropdown

  • November 15, 2012
  • 2 replies
  • 5427 views

I have the following simple dropdown on my form:

---------------------------------------------------------

                          <select name="ttTo" id="ttTo" >

                            <option value="">Choose One</option>

                            <cfoutput query="rsTicketTo">

                              <option value="#rsTicketTo.ttEmail#">#rsTicketTo.ttDesc#</option>

                            </cfoutput>

                          </select>

                        </div>

--------------------------------------------------------

How would I change my select above to include the sample functionality below but using ColdFusion?

Note: The #TicketType# variable below will be on the page but not from the same table as the ttTo value.

       // Check where to send support request to...

       switch (trim($fTicketTo))

       {

       case "":

$error = 1;

$tMessage = "You must select a valid Recipient!";

break;

       case "Service":

if ($fTicketType == "T1")

{

$fTicketTo = 'serv1@xyz.com';

}

else

{

$fTicketTo = 'serv2@xyz.com';

}

break;

       case "Outage":

$fTicketTo = 'serv1@xyz.com';

break;

       case "Data":

$fTicketTo = 'data@xyz.com';

break;

       case "Voice":

$fTicketTo = 'voice@xyz.com';

break;

       case "T1":

$fTicketTo = 't1@xyz.com';

break;

       case "Wire":

$fTicketTo = 'wire@xyz.com';

break;

       case "Phone":

$fTicketTo = 'pst@xyz.com';

break;

       case "Prov":

$fTicketTo = 'prov@xyz.com';

break;

       case "Cust":

$fTicketTo = 'cc@xyz.com';

break;

       }

    This topic has been closed for replies.

    2 replies

    BKBK
    Community Expert
    Community Expert
    November 16, 2012

    It isn't clear which query column corresponds to the case values 'service', 'outage', 'data', etc. There are also inconsistenties. You have defined the cases as subsequent values of trim($fTicketTo). Yet, within each case block, you again define a new variable of the same name ($fTicketTo). Another inconsistency is that "T1" is at once a value for $fTicketType and for trim($fTicketTo).

    If all you wished to do is to convert the given switch-case into a select-box, then you could proceed as follows:

    <cfform>

    <cfselect name="ttTo" id="ttTo" required="yes" message="You must select a valid Recipient!">

    <option value="">Choose support request</option>

    <option value="serv1@xyz.com">T1 Service</option>

    <option value="serv2@xyz.com">Service(except T1)</option>

    <option value="serv1@xyz.com">Outage</option>

    <option value="data@xyz.com">Data</option>

    <option value="voice@xyz.com">Voice</option>

    <option value="t1@xyz.com">T1</option>

    <option value="wire@xyz.com">Wire</option>

    <option value="pst@xyz.com">Phone</option>

    <option value="prov@xyz.com">Prov</option>

    <option value="cc@xyz.com">Cust</option>

    </cfselect>

    <cfinput name="sbmt" type="submit" value="Submit">

    </cfform>

    Inspiring
    November 16, 2012

    Using switch/case inside a select control doesn't make any sense.  What are you hoping to accomplish?

    jligAuthor
    Inspiring
    November 16, 2012

    The drop-down is filled with values from a query.

    - and each value has an associated email address

    - most of the time the value selected will go to its associated email

    - but occasionally, depending on an a value in a 2nd drop-down, I need the associated email to be different (see the code above, where ticketType=T1)

    Inspiring
    November 16, 2012

    In that case, my first choice would be to use the case construct in the actual query to get the appropriate email address.