JavaScript Fall Through Switch Statements
Someone recently asked me if it were possible to easily execute the same code for two or more possible case values in a JavaScript switch statement.
Quite simply, the answer is yes. In this example, I'm working with a form that's fairly multipurpose as in depending upon the user's selections we want to show and hide different divs as well as set some control values by default and possibly restrict use of other controls.
This is a CF app that makes use of jQuery for basic UI functionality. In this case (pun intended), I need to show/hide the same controls and divs for two options in a cfselect that I'm grabbing the value of in the top of my JavaScript function below...
2 var routeStyle = ColdFusion.getElementValue('routeToID', 'outputEntry', 'value');
3 switch(routeStyle){
4 //Containerize Temp - Suspended Job goes to Work In Process
5 case '-1' :
6 $("#containerWorksheetA").show();
7 $("#containerWorksheetB").show();
8 $("#containerWorksheetC").show();
9 $("#containerWorksheetD").hide();
10 $("#containerWorksheetE").hide();
11 document.outputEntry.containerize.value = true;
12 document.outputEntry.statusCode.value = 14;
13 document.outputEntry.statusCode.disabled = true;
14 break;
15
16 //Containerize Final
17 case '-2' :
18 $("#containerWorksheetA").show();
19 $("#containerWorksheetB").show();
20 $("#containerWorksheetC").show();
21 $("#containerWorksheetD").hide();
22 $("#containerWorksheetE").hide();
23 document.outputEntry.containerize.value = true;
24 document.outputEntry.statusCode.value = 16;
25 document.outputEntry.statusCode.disabled = false;
26 break;
27
28 //Discard Material
29 case '-3' :
30 $("#containerWorksheetA").show();
31 $("#containerWorksheetB").show();
32 $("#containerWorksheetC").show();
33 $("#containerWorksheetD").hide();
34 $("#containerWorksheetE").hide();
35 document.outputEntry.containerize.value = true;
36 document.outputEntry.statusCode.value = 11;
37 document.outputEntry.statusCode.disabled = true;
38 break;
39
40 //this case is a fall through which handles init and separator values where controls are hidden
41 case '0' : case 'sep' :
42 $("#containerWorksheetA").hide();
43 $("#containerWorksheetB").hide();
44 $("#containerWorksheetC").hide();
45 $("#containerWorksheetD").hide();
46 $("#containerWorksheetE").hide();
47 document.outputEntry.statusCode.disabled = false;
48 break;
49
50 //this case applies to Step Driven Route scenarios
51 default :
52 $("#containerWorksheetA").show();
53 $("#containerWorksheetB").hide();
54 $("#containerWorksheetC").hide();
55 $("#containerWorksheetD").hide();
56 $("#containerWorksheetE").show();
57 document.outputEntry.statusCode.disabled = false;
58 break;
59 }
60 }
It's pretty easy but in case you didn't see it the fall through statement happens in the case of "case '0' : case 'sep' :". Just to play fair I will mention that some developers do not agree with this style of syntax but in my view as long as you're commenting each case then you're not leading anyone astray.

You can use if statements to compare the selected option like...
if (selectedHour >= 1 && selectedHour <= 12){
alert('Good Morning');
}
or you can use a switch/case syntax.
Inside of your switch statement just do this...
case '1' : case '2' : case '3' //go all the way up to your max allowed...
alert('Good Morning');
break;
In my opinion the if statements will be cleaner to maintain and understand.
http://www.btscene.com
http://eventsearch.us
http://www.wotlk-powerleveling.com http://www.uweddingdress.com wedding dresses
http://simulationassuranceauto.org
` ?—? ? ??`_?
????????????? ohne Vertrag,
????????????? Handy ohne Simlock?
??????????????Sciphones i68,
?????????????Touchscreen Handys und
????????????? Handy Zubeh?
????????????? re von Elektronik-
?——???????——?Grosshandel in
?????????? http://www.efox-shop.com/.
?????????? ??????
????????????????
http://www.guccihandbagsoutlet.com/ gucci outlet online
http://www.guccihandbagsoutlet.com/ gucci handbags
http://www.coachoutletmalls.com/ coach bags
http://www.coachoutletmalls.com/ coach bags outlet
http://www.cheap-mbt-shoes.net cheap mbt shoes
http://www.cheap-mbt-shoes.net walking shoes
http://www.monclerjacketsstore.com Moncler Store
http://www.monclerjacketsstore.com/Moncler-Down-Jackets.html" target="_blank">http://www.monclerjacketsstore.com/Moncler-Down-Ja... Moncler Down Jackets
<a href=http://www.locations4business.com/europe/UK/nation... skill information</a>
all kinds of wedding dresses<a href=“http://www.sanseed.com”>weedding dresses</a>
all kinds of cosplay costumes
all kinds of creative gifts
all kinds of wigs and hairpieces
all kinds of holiday and party supplies
all kinds of electronics
Just believe in us and join.
http://www.sanseed.com/" target="_blank">http://www.sanseed.com/