Drop Down Menu With Frames

A drop down menu can be targeted to another frame. For example, suppose that you have a dropdown in the upper frame of a framed page, and you want to target it at the lower frame. We might create this sort of frameset with the following code. Notice that we name the lower frame MAIN:

<FRAME SRC="ddf.titlebar.html" NAME=TITLEBAR>
<FRAME SRC="ddf.lower.html"    NAME=MAIN>

To create a drop down menu in the upper frame, we'll use the same script as described in the previous page. Copy the following script exactly as-is into the <HEAD> section of your page:

<SCRIPT TYPE="text/javascript">
function dropdown(mySel)
var myWin, myVal;
myVal = mySel.options[mySel.selectedIndex].value;
if(mySel.form.target)myWin = parent[mySel.form.target];
else myWin = window;
if (! myWin) return true;
myWin.location = myVal;
return false;

The dropdown will use a select form like in the previous example. To target the dropdown at the lower frame we'll make one small change. In the <FORM ...> tag add a TARGET attribute targeting the form at the MAIN frame:

this code produces this
METHOD=POST onSubmit="return dropdown(this.gourl)"
<SELECT NAME="gourl">
<OPTION VALUE="">Choose a Destination...
<OPTION VALUE="ddf.lower.html">Home
<OPTION VALUE="ddf.user.html">User Manuals
<OPTION VALUE="ddf.resume.html">Resume
<OPTION VALUE="ddf.contact.html">Contacts
the dropdown in this page

This select works almost the same as that in the previous page. The Javascript checks if the <FORM ...> has a TARGET attribute. If it finds one, it redirects the indicated frame instead of the current frame. If the browser has Javascript turned off then it uses the TARGET attribute anyway when it is redirected by our redirection CGI.

About the Author
Copyright 1997-2002 Idocs Inc. Content in this guide is offered freely to the public under the terms of the Open Content License and the Open Publication License. Contents may be redistributed or republished freely under these terms so long as credit to the original creator and contributors is maintained.