Name
switch/case — NN 4 IE J3 ECMA n/a
Synopsis
Provides a shortcut to execution paths for numerous conditions of an expression.
Syntax
switch (expression
) { caselabel1
:statements
[break] caselabel2
:statements
[break] ... [default:statements
] }
Example
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" }
Get Dynamic HTML: The Definitive Reference now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.