cfscript - switch, case, default statement in script
cfscriptSwitch.cfm
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>How to use switch, case, default statement in cfscript tag</title>
</head>
<body>
<h2 style="color:DodgerBlue; font-style:italic">cfscript example: switch statement</h2>
<hr width="350" align="left" color="PaleVioletRed" />
<br />
<cfform name="HelloForm" method="post">
Favorite Color:
<cfinput type="text" name="FavColor">
<cfinput name="Submit" type="submit" value="Submit">
</cfform>
<br />
<cfscript>
if (IsDefined("Form.Submit") and (Form.FavColor neq ""))
{
switch(Form.FavColor){
case "Crimson":
WriteOutput("Crimson is red type color");
break;
case "DodgerBlue":
WriteOutput("Crimson is blue type color");
break;
case "SeaGreen":
WriteOutput("Crimson is green type color");
break;
default:
WriteOutput("You input an unknown color.");
}
}
</cfscript>
</body>
</html>