Program:
Output:
<!DOCTYPE html>
<html>
<head>
<script type='text/JavaScript'>
syco = new Array('C++','DBMS','DSU');
tyco = new Array('AdvJava','JavaScript','Python');
function getSubject(yearselected)
{
for(i = document.f1.Subject.options.length-1 ; i>0 ; i--)
{
document.f1.Subject.options.remove(i);
}
classselected = yearselected.options[yearselected.selectedIndex].value;
if(classselected != "")
{
if(classselected == "1")
{
for(i=1;i<=syco.length;i++)
{
document.f1.Subject.options[i] = new Option(syco[i-1]);
}
}
if(classselected == "2")
{
for(i=1;i<=tyco.length;i++)
{
document.f1.Subject.options[i] = new Option(tyco[i-1]);
}
}
}
}
</script>
</head>
<body>
<form name="f1">
<select name="Class" onchange="getSubject(this)">
<option value="0"> Class </option>
<option value="1"> SYCO </option>
<option value="2"> TYCO </option>
</select>
<select name="Subject">
<option value="0"> Subject </option>
</select>
</form>
</body>
</html>
Output: