July 1998
Intermediate to advanced
1456 pages
65h 5m
English
switch/case — NN 4 IE J3 ECMA n/a
Provides a shortcut to execution paths for numerous conditions of an expression.
switch (expression) { caselabel1:statements[break] caselabel2:statements[break] ... [default:statements] }
var productList = document.forms[0].prodList
var chosenItem = productList.options[productList.selectedIndex].value
switch(chosenItem) {
case "Small Widget":
document.forms[0].price.value = "44.95"
break
case "Medium Widget":
document.forms[0].price.value = "54.95"
break
case "Large Widget":
document.forms[0].price.value = "64.95"
break
default:
document.forms[0].price.value = "Nothing Selected"
}Read now
Unlock full access