Exp 14
Exp 14
14
Aim: Develop a web page for implementing menu.
Theory:
Creating a Pull-Down Menu:
A pull-down menu is used to make it easy for visitors to navigate a complex web site.The menu can reflect a
common theme among web pages, and each menu option can have a web page/function associated with it.
You can use JavaScript to load the selected page when any option from menu is selected by the visitor.
1. Create a menu with <select> tag and add options to it using <option> tag.
2. Specify url of web page to be opened when an option is selected by visitor, in value property of <option> tag.
<select name="MenuChoice" onchange="DisplayPage(this)">
<option>Products</option>
<option value="page2.html">Computers</option>
<option value="page3.html">Monitors</option>
</select>
3. Call function using onchange event in <select> tag.
<select name="MenuChoice" onchange="DisplayPage(this)">
This pointer is passed as parameter that represents menu control(selected option).
4. Define function body inside <script> tag.
<script type="text/javascript">
function DisplayPage(Choice)
{
Page = Choice.options[Choice.selectedIndex].value;
if (Page != "")
{
window.location = Page;
}}
</script>
Location property stores address of web page to be opened once an option is selected from menu.
function Getsubjects(Semester)
{
for(i=document.Form1.subjects.options.length-1;i>0; i--)
{
document.Form1.subjects.options.remove(i) //Clear existing
options from subjects
}
semvalue = Semester.options[Semester.selectedIndex].value; //
finding selected semester from sem menu
if (semvalue != "")
{
if (semvalue == '1')
{
for (i=1; i<=fifthsem.length;i++)
{
document.Form1.subjects.options[i] =new Option(fifthsem[i-1]);
// loading options from array into subjects menu for fifth sem
}
}
if (semvalue == '2')
{
for (i=1; i<=sixthsem.length;i++)
{
document.Form1.subjects.options[i] =new Option(sixthsem[i-1]);
// loading options from array into subjects menu for sixth sem
}
}
}
}
</script>
</head>
<body onload="document.Form1.Semester.selectedIndex=0">
<form name="Form1">
<select name="Semester" onchange="Getsubjects(this)"> // First
menu as semester
<option value="0">Semester</option>
<option value="1">Fifth</option>
<option value="2">Sixth</option>
</select>
Conclusion:
With all the concepts based on crating menu , successfully executed all programs with correct output.