Here you can find a number of examples on Java Script.Please find the various kinds of examples listed on the right side of this site. If you don't find anything on Java Script then please write to us or leave a commnet. We are pleased to help and find the solution of your problem.

Javascript: Switch Case



<html>
<head>
<title>Switch case</title>

<script language="javascript">
function calc()
{
var n1=f1.t1.value;
var n2=f1.t2.value;
switch(f1.opr.value)
{
case "+":
f1.result.value=Number(n1) + Number(n2);
break;
case "-":
f1.result.value=n1-n2;
break;
case "*":
f1.result.value=n1*n2;
break;
case "/":
f1.result.value=n1/n2;
}
</script>

</head>
<body>

<form name="f1">
<input type="text" name="t1">
<select name="opr">
<option value="+"> +
<option value="-"> -
<option value="*"> *
<option value="/"> /
</select>
<input type="text" name="t2">
<input type="button" value="Calculate" onclick="calc()">
<input type="text" name="result">
</form>

</body>
</html>

No comments:

Post a Comment

Google