Exp11 3
Exp11 3
<html>
<head>
<script>
array = new Array("Ram", "Pavan", "Mira");
array1 = new Array("Ajay", "Mary", "Riya");
function disp(obj)
{
for (i = document.f1.department.options.length - 1; i >= 0; i--)
{
document.f1.department.options.remove(i);
}
dept = obj.options[obj.selectedIndex].value;
if (dept == "1")
{
for (i = 0; i < array.length; i++)
{
document.f1.department.options[i] = new Option(array[i]);
}
}
if (dept == "2")
{
for (i = 0; i < array1.length; i++)
{
document.f1.department.options[i] = new Option(array1[i]);
}
}
}
</script>
</head>
<body>
<form name="f1">
<select name="dept" onchange="disp(this)">
<option value="o">Departments</option>
<option value="1">Computer</option>
<option value="2">Information Technology</option>
</select>
<select name="department">
<option value="o">Employees</option>
</select>
</form>
</body>
</html>
Output: