Forum : Switch prom
Brief description  about Online courses   join in Online courses
View Alok Ranjan Rai 's Profile

Switch prom

Dear Sir,
I have type this code, but i did get proper answer.
so please tell where is problems.
<html>
<head><title> switch statement</title>

<Script language="JavaScript">
Age = document.frmOne.cmbAge.value
switch (Age) {
case "1":
alert("still at school")
break
case "2":
alert("still young")
break
case "3":
alert("start lying")
break
case "4":
alert("start saving")
break
default:
alert("undetermined")
}
</script>
</head>
<body>
<form name=frmOne>
<select name = cmbAge>
<option value = 1>5 to 16</option>
<option value = 2>17 to 30</option>
<option value = 3>31 to 45</option>
<option value = 4>46 </option>
</select>
</form>
</body>
</html>
Asked by Alok Ranjan Rai | Feb 11, 2011 |  Reply now
Replies (2)
View teacher siliconindia 's Profile
Hi Alok
U did not bind event to selector, below is correct code

<html xmlns="http://www.w3.org/1999/xhtml">
<head><title> switch statement</title>

<script type="text/javascript">
function agedetermine()
{
var Age=Number(document.frmOne.cmbAge.value);
switch (Age) {
case 1:
alert("still at school");
break;
case 2:
alert("still young");
break;
case 3:
alert("start lying");
break;
case 4:
alert("start saving");
break;
default:
alert("undetermined");
}
}
</script>

</head>
<body>
<form name="frmOne">
<select name = "cmbAge" onchange="agedetermine()">
<option value = "1" selected="selected">5 to 16</option>
<option value = "2">17 to 30</option>
<option value = "3">31 to 45</option>
<option value = "4">46 </option>
</select>

</body>
</html>
Feb 24, 2011
View teacher siliconindia 's Profile
Hi Alok,
Send this code to below given id

vishwanath@siliconindia.com
Feb 14, 2011