Switch- By using switch statement we can check multiple expressions/conditions and execute their related statements otherwise default statement will execute.
E.g.
Switch Statement
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:
- JavaScript Introduction
- Variables in JavaScript
- JavaScript Function
- Accessing JavaScript Function
- Creating JavaScript interactive form
- Accessing form field value
- Creating interactive form login webpage
- Networking Fundamentals
- TCP/IP and Internet addressing
- Internet Working
- Internet Working Servers
- Concept and need for web publishing
- Web languages
- Javascript Control Structure
- Checking Text is Letter/s
- Checking Text is Number/s
- Checking Textbox is Empty or not
- Addition of two numbers
- Subtraction of two numbers
- Multiplication of two numbers
- Division of two numbers
- Form field validations
- Email validation