Switch

Switch- By using switch statement we can check multiple expressions/conditions and execute their related statements otherwise default statement will execute.

E.g.

<html>
<head>
<title>Switch Statement</title>
</head>
<body>
<form name="form1">
Enter your grade (A to E):<input type="text" name="grd">
<input type="button" onclick="check()" value="Check">
</form>
<script language="JavaScript">
function check()
{
var a = document.form1.grd.value;
switch(a)
{
case"A":alert("Excellent");
break;
case"B":alert("Pretty Good");
break;
case"C":alert("Passed");
break;
case"D":alert("Not so good");
break;
case"E":alert("Failed");
break;
default:alert("Unknown grade");
}
}
</script>
</body>

</html>
Check Output: Switch Statement
Enter your grade (A to E):
Related Topics:
  1. JavaScript Introduction
  2. Variables in JavaScript
  3. JavaScript Function
  4. Accessing JavaScript Function
  5. Creating JavaScript interactive form
  6. Accessing form field value
  7. Creating interactive form login webpage
  8. Networking Fundamentals
  9. TCP/IP and Internet addressing
  10. Internet Working
  11. Internet Working Servers
  12. Concept and need for web publishing
  13. Web languages
  14. Javascript Control Structure
  15. Checking Text is Letter/s
  16. Checking Text is Number/s
  17. Checking Textbox is Empty or not
  18. Addition of two numbers
  19. Subtraction of two numbers
  20. Multiplication of two numbers
  21. Division of two numbers
  22. Form field validations
  23. Email validation