newbie: problem with dropdownbox, navigation and frames

M

Mike

Hi i'm trying to the following:
a 3 frame page; parent, left en right (name of right one is "main")

i want to have a dropdownbox in the top frame to navigate to some url's.

i use the following code ( i found somewhere):

<head>
<base target="main">
<script language="JavaScript"><!--
function goThere(form){
var linkList=form.selectThis.selectedIndex

if(!linkList==""){window.location.href=form.selectThis.options[linkList].val
ue;}
}
//--></script>
</head>
<body>
<p align="left"><form name="dropMenu">
<select name="selectThis" size="1" onChange="goThere(this.form);">
<option selected value="">Whereto?
<option value="http://www.somewhere1.com/">Somehwere1</option>
<option value="http://www.somewhere2.com/">Somewhere2</option>
<option value="http://www.somewhere3.com/">Somewhere3</option>
</select></p>
</form>
</body>

The problem is that the URL is opened in the topframe. How do i get the new
URL opened in the "main" frame? I guess it has something to do with
window.location.href...

Thanx in advanced.

Mike
 
M

Mike

Lasse,

thanx!
It is fot my own website whcih will be functioning as sort of a bookmark
page, so probably i will be the only one using it.

just one more question and then i'll stop bothering you and buy a book on
programming..:)

I would like one of the select options (for example the first) not to open
in this frame but in the same window (like it was). Any possiblilitie of
doing that easily?

TIA

Mike


Lasse Reichstein Nielsen said:
Mike said:
Hi i'm trying to the following:
a 3 frame page; parent, left en right (name of right one is "main")

i want to have a dropdownbox in the top frame to navigate to some url's.
i use the following code ( i found somewhere):

The code is not that good, but it will do.
<head>
<base target="main">
<script language="JavaScript"><!--

<script type="text/javascript">

The type attribute is required and the language attribute is deprecated.
You don't need HTML comments in Javascript code.
function goThere(form){
var linkList=form.selectThis.selectedIndex

if(!linkList==""){window.location.href=form.selectThis.options[linkList].val
ue;}

Change this to
function goThere(form) {
var select = form.elements['selectThis'];
var idx = select.selectedIndex;
if (idx != 0) {
window.open(select.options[idx].value,"main");
}
}
or
function goThere(form) {
var select = form.elements['selectThis'];
var idx = select.selectedIndex;
if (idx != 0) {
window.frames['main'].document.location.href = select.options[idx].value;
}
}


}
//--></script>
</head>
<body>
<p align="left"><form name="dropMenu">
<select name="selectThis" size="1" onChange="goThere(this.form);">

Making a destructive change, as changing the page, base on an onchange
event on a select element, will make the page inaccesible to people
navigating with a keyboard. They can never reach the second option without
hitting the first one first. That is why a "Go" button is a better idea.
The problem is that the URL is opened in the topframe. How do i get the new
URL opened in the "main" frame? I guess it has something to do with
window.location.href...

See above.
/L
 
M

Mike

Lasse,

thanx!

mike

Lasse Reichstein Nielsen said:
Mike said:
I would like one of the select options (for example the first) not to open
in this frame but in the same window (like it was). Any possiblilitie of
doing that easily?

If the different options should act differently, then the most general
method would be to add information to each option about which frame it
should open in.
E.g.
<select ...>
<option value="_top|http://www.google.com/"> Google </option>
<option value="main|http://example.com/"> somewhere </option>
<option value="main|http://www.example.com/"> somewhere else </option>
</select>

Then you split the value into frame and url, and open the url in that
frame. Example code for the goThere function (where a missing "|" means
that you use a default target of "_top"):

function goThere(form) {
var select = form.elements['selectThis'];
var idx = select.selectedIndex;
if (idx != 0) {
var frame="_top";
var url = select.options[idx].value;
var idx = url.indexOf("|");
if (idx!=-1) {
frame=url.substring(0,idx);
url=url.substring(idx+1);
}
window.open(url,frame);
}
}

Untested code.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top