PDA

View Full Version : Drop down menu in a form


wormington
06-19-2005, 04:21 PM
Hi

I'm trying to put a drop down menu in a header frame that changes the pages in the main frame.
Some of the items in my drop down menu are headings and not menu items but they cause problems ie the header page loads in the main frame. What can I do to make nothing happen if a Heading is clicked on and not a menu item.

Here is the code for my drop down menu:-

<form>

<select class="bluemenu" onChange="top.frames['main'].location=this.options[this.selectedIndex].value;">
<option value="#nowhere">Choose an option</option>
<optionvalue="#nowhere">--------------------------------</option>
<option value="#nowhere">HELICOPTERS SALES</option>
<option value="alouettes.htm">Alouette</option>
<option value="agusta.htm">Agusta</option>
<option value="augusta_bell.htm">Bell</option>
<option value="brantly.htm">Brantly</option>
<option value="engstrom.htm">Enstroms</option>
<option value="eurocopter.htm">Eurocopter</option>
<option value="gazelles.htm">Gazelles</option>
<option value="hughes_schweitzer.htm">Hughes/Schweizer</option>
<option value="macdonald.htm">MD Helicopters</option>
<option value="robinsons.htm">Robinsons</option>
<option value="rotorway.htm">Rotorway</option>
<option value="westlandscout.htm">Westland Scout</option>
<option value="#nowhere">--------------------------------</option>

</select>

</form>

Thanks for any help

Wormington

mark87
06-19-2005, 04:32 PM
I guess you could make a function like so then run it -

<script>
function ChangeLinks() {
if (YOURSELECTNAME.options[YOURSELECTNAME.selectedIndex].value="#nowhere"){
}
else{
top.frames['main'].location=YOURSELECTNAME.options[YOURSELECTNAME.selectedIndex].value;
}
</script>

onChange="ChangeLinks()"

wormington
06-19-2005, 04:58 PM
Thanks for the reply, can you tell me what to put where, I'm a bit of a numbskull.

Thanks

sesshyzkidz
06-19-2005, 05:22 PM
The script can go in either the head or the body, I think. As for the onChange event, put that in your select element.

<body>
<!-- skipping some code -->
<script>
function ChangeLinks() {
if (YOURSELECTNAME.options[YOURSELECTNAME.selectedIndex].value="#nowhere"){
}
else{
top.frames['main'].location=YOURSELECTNAME.options[YOURSELECTNAME.selectedIndex].value;
}
</script>
<!-- skipping some more code -->
<select onChange="ChangeLinks()">

wormington
06-19-2005, 08:50 PM
OK, I've got this in my header code:

<script>
function ChangeLinks() {
if (YOURSELECTNAME.options[YOURSELECTNAME.selectedIndex].value="#nowhere"){
}
else{
top.frames['main'].location=YOURSELECTNAME.options[YOURSELECTNAME.selectedIndex].value;
}
</script>

and this in the select tag

<select onChange="ChangeLinks()">

Now nothing happens at all when I click on the menu, at least before I was getting the required pages

What am I doing wrong? does the YOURSELECTNAME refer to anything?

_Aerospace_Eng_
06-19-2005, 08:52 PM
YOURSELECTNAME refers to the name of your select menu and according to the previous code you posted you don't have a name for the menu. Try this, give your select menu a name of "bluemenu" and use this for your script.
<script type="text/javascript">
function ChangeLinks() {
if (document.forms[0].bluemenu.value!="#nowhere"){
top.frames['main'].location=document.forms[0].bluemenu.options[document.forms[0].bluemenu.selectedIndex].value;
}
}
</script>
which goes in your head tags.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
<script type="text/javascript">
function ChangeLinks() {
if (document.forms[0].bluemenu.value!="#nowhere"){
top.frames['main'].location=document.forms[0].bluemenu.options[document.forms[0].bluemenu.selectedIndex].value;
}
}
</script>
</head>

<body>
<form>
<select class="bluemenu" name="bluemenu" onChange="ChangeLinks()">
<option value="#nowhere">Choose an option</option>
<option value="#nowhere">--------------------------------</option>
<option value="#nowhere">HELICOPTERS SALES</option>
<option value="alouettes.htm">Alouette</option>
<option value="agusta.htm">Agusta</option>
<option value="augusta_bell.htm">Bell</option>
<option value="brantly.htm">Brantly</option>
<option value="engstrom.htm">Enstroms</option>
<option value="eurocopter.htm">Eurocopter</option>
<option value="gazelles.htm">Gazelles</option>
<option value="hughes_schweitzer.htm">Hughes/Schweizer</option>
<option value="macdonald.htm">MD Helicopters</option>
<option value="robinsons.htm">Robinsons</option>
<option value="rotorway.htm">Rotorway</option>
<option value="westlandscout.htm">Westland Scout</option>
<option value="#nowhere">--------------------------------</option>

</select>

</form>
</body>
</html>

wormington
06-19-2005, 09:26 PM
Fantastic!!

Thank you very very much