Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using frames in JavaScript

Status
Not open for further replies.

DoNotEven

Programmer
Dec 21, 2000
89
US
How do you make a window open in a frame with JavaScript. TARGET="HOME" does not work. My frame windows keep opening in the same frame my list box is in, I want them to open in the other frame window.

Here is the JavaScript I am using:
function showpage(form)
{ var item = form.list.selectedIndex;
choice = form.list.options[item].value;
if (choice=="fbi") { fbi(); } else
if (choice=="aff") { aff(); } else
if (choice=="com") { com(); } else
if (choice=="contest") { contest(); } else
if (choice=="kwd") { kwd(); } else
if (choice=="snake") { snake(); } else
if (choice!="x")
location.href=""+(choice);
};

The frame window I want it to open in is NAME=HOME which is the bottom window.
I am just using two frames.
The top frame has my list box in it which I want to stay there all the time. I want the selections made from the list box to open into the bottom frame. BUT they are opening in the list box frame, which is the top frame.

The if (choice=="") statements open popup windows and they work just fine.

 
Ok .... I figured it out....wow so easy to...hahaha

Here is what worked for me:function showpage(form)
{ var item = form.list.selectedIndex;
choice = form.list.options[item].value;
if (choice=="fbi") { fbi(); } else
if (choice=="aff") { aff(); } else
if (choice=="com") { com(); } else
if (choice=="contest") { contest(); } else
if (choice=="kwd") { kwd(); } else
if (choice=="snake") { snake(); } else
if (choice!="x")
top.home.location.href=""+(choice);
};

top.home put it in my bottom frame....

So I have it solved....


 
The frameset page is called the parent, relative to the individual frames, communicate through that.

i.e.parent.bottom

-Ben "Alright whatever man, I'll hook up the hair, but I aint touchin the ring...Cause I'm still a pla--yer"
 
Ben, top refers to the upper-most frameset. Parent refers to the next higher frameset. If you've only got one, then they are the same thing. If you've got frames within frames then they're not.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Ok thanks...Parent does make more sence...and I did think of using it but put in TOP and it worked...yes I only have two frames...thanks again...

Now I have another question?

How can you with JavaScript make a menu visable on a page in the spot you want it visable at....and have the menu in another file so all your pages can use it. I do use remote .js files but I cannot figure out how to keep all the menu code in a remote file that can be shared by all the pages and have it displayed in another page where I want it to be displayed.

document.write(""); creates a new file and covers the other things on my page.

This is the reason I went to a two frame page.

If someone could send me some sample JavaScript that will do what I want it sure would help me out.

I am trying to make my job easy, I am getting tired of all the typing and redoing the menu's everytime I add to a web site.

Keep in mind all the menu code has to be in a remote file all the pages can share. And then be displayed by reference to it from any page.
 
just a detail, but switch/case is more efficient and readable than many if else
 
Thank you iza....and I just love using GOTO in C and C++...hahahaha

would this work?

function showpage(form)
{ var item = form.list.selectedIndex;
choice = form.list.options[item].value;

switch(choice)
{
case fbi: fbi(); break;
case aff: aff(); break;
case com: com(); break;
case contest: contest(); break;
case kwd: kwd(); break;
case snake: snake(); break;
case x: return(0);
}
break;

parent.home.location.href=""+(choice);
};

I am new to JavaScript....
 
yes, it should be working fine ! let me know (anyway using if ... if ... if ... or switch case ... shouldn't change anything, it's just a matter a details!)
 
Ok iza when I get time I will try it and see if it works...right now I am busy fixing HTML errors on web pages that someone thought they knew what they were doing when the did it....hahahaha Oh well we all have to learn...seams like it all changes so fast I cannot keep up with it all...hahahaha I programed in Pascal, C, C++ and now in Borland Builder 3 (about to update) which is a mixture of many languages. Now I am learning JavaScript, Perl and asp. And I need to start in on Flash real soon. Just not enough time for an old fart like me....hahahaha Oh yes and I want to learn Java...hahahaha Back to work...and thanks
 
to me if you know object oriented programming and C then it's really easy to learn C++, and then even easiest to learn java, and even even even easiest to learn javascript (in this order !!!! the other way (javascript-> java-> c++) is tough !) - if you've done a minimum of shell coding then it's also easy to learn perl and php ...
i don't think the hardest think to learn is a new language, it's the way of thinking that is behind the language that can sometimes be tough
and yes i know well about those "someone thought they knew what they were doing when the did it" - i've been working with them as well ;]
 
To create a menu on your page via js and not overwrite your content, create a new layer and then write() to that.
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Ok Tom thanks...hey Tom my Name is Bob Anderson you never know we could be from the same clan of Anderson's.


 
This is waaaaay off topic, but what the hey. My name is not the Scottish Anderson, but an adopted misspelling of Andersen, from Andreesen, which is Swedish. Though I am actually related to the Scottish clans Gunn and Hood (as in Robin Hood).
Sincerely,

Tom Anderson
CEO, Order amid Chaos, Inc.
 
Ok Tom....hey Tom where could I find "on the web" the manual for JavaScript...it is kind of hard for me to learn JavaScript without the manual...but I have been doing it...

Thanks
 
Hey there I have tried to make a menu in Flash 5, and tried incorporating it into two frames. I wish the menu in the left frame to control what is viewed in the right frame. However it refreshes the left frame which is JUST STUPId. After some research I heard that javascript may be the only solution do you people think you can help me? never worked with Java before. i would really appreciate it if you could direct me to the javascript codes I need, and where to use them. Thankyou very much. If you solve the problem I'll link you to the site as soon as possible. If none of this made any sense please analyse what I am saying by visiting the flash version of the site! thankyou for your time.
 
You cna do it with HTML:

Index.html:
<!doctype html public &quot;-//w3c//dtd html 4.0 transitional//en&quot;>
<html>
<head>
<title>The Pines Resort</title>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;text/html; charset=iso-8859-1&quot;>
<META NAME=&quot;keywords&quot; CONTENT=&quot;vacation, vacations, resort, resorts, resorts on lake, year around resort, vacation cabins, winter resorts, winter resort&quot;>
<META NAME=&quot;description&quot; CONTENT=&quot;The Pines Resort on Long Lake a year around resort, Cheboygan, Michigan, Bar, Restaurant, Cabins, Boats&quot;>
<META NAME=&quot;author&quot; CONTENT=&quot;Webmaster Bob Anderson&quot;>
<META NAME=&quot;generator&quot; CONTENT=&quot;</head>
<frameset rows=&quot;100,*&quot; border=0>
<frame src=&quot;window2.html&quot; noresize scrolling=no marginwidth=30>
<frameset cols=&quot;110,*&quot; border=0>
<frame src=&quot;window1.html&quot; noresize scrolling=no FRAMEBORDER=0>
<frame src=&quot;home.html&quot; name=home> <!-- this is the right frame -->
</frameset>
</frameset>
</html>

Window1.html: Left frame:
<html>
<head>
<title>window 1</title>
<STYLE TYPE=&quot;text/css&quot;>
<!--
A:link {color:&quot;#FFFFFF&quot;;}
A:visited {color:&quot;#FFFFFF&quot;;}
A:hover {color:&quot;#FF0000&quot;;}
b {font-size: 11pt; font: bold;}
-->
</STYLE>
</head>
<body background=&quot;images/pinebk9.jpg&quot; text=&quot;#FFFFFF&quot;>

<div align=center>
<b><a href=&quot;home.html&quot; target=&quot;home&quot;>Home</a></b>
<br>
<b><a href=&quot;cabins.html&quot; target=&quot;home&quot;>Cabins</a></b>
<br>
<b><a href=&quot;lake.html&quot; target=&quot;home&quot;>Long Lake</a></b>
<br>
<b><a href=&quot;bar.html&quot; target=&quot;home&quot;>Restaurant</a></b>
<br>
<b><a href=&quot;rates.html&quot; target=&quot;home&quot;>Rates</a></b>
<br>
<b><a href=&quot;maps.html&quot; target=&quot;home&quot;>Maps</a></b>
<br>
<b><a href=&quot;res.html&quot; target=&quot;home&quot;>Reservations</a></b>
<b><a href=&quot;area.html&quot; target=&quot;home&quot;>Attractions</a></b>
<br>
<b><a href=&quot;snowmobile.html&quot; target=&quot;home&quot;>Snowmobile</a></b>
<b><a href=&quot;service.html&quot; target=&quot;home&quot;>Services</a></b>
<br>
<b><a href=&quot;deer.html&quot; target=&quot;home&quot;>Fallow Deer</a></b>
<br>
<b><a href=&quot;mailto:the_pinesresort@yahoo.com&quot; target=&quot;home&quot;>E-Mail</a></b>
<br>
<b><a href=&quot; target=&quot;home&quot;>Guestbook</a></b>
<br>
</div>
</body>
</html>

Window2.html: top frame:
<html>
<head>
<title>window 2</title>
<STYLE TYPE=&quot;text/css&quot;>
<!--
A:link {color:&quot;#FFFFFF&quot;;}
A:visited {color:&quot;#FFFFFF&quot;;}
A:hover {color:&quot;#FF0000&quot;;}
-->
</STYLE>
</head>
<body background=&quot;images/phead9.jpg&quot;>
<b><a href=&quot;sitemap.html&quot; target=&quot;home&quot;><font size=&quot;-1&quot;>Site Map</font></a></b>
</body>
</html>

This is a 3 frame web page, Header in the top frame, Menu in the left frame, Web Pages in the right frame.
 
Thankyou for your response so quickly going to attempt a familiar task thankyou. Tell you how I get on!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top