Solved

Java Programming question

Posted on 1997-07-28
12
181 Views
Last Modified: 2010-04-16
In the following script, the button is supposed to call a new page of html to open in another frame on the same page as the button.

The "target=" seems to me to be in the correct place, but the files open in the same frame as the button. What am I missing?

<script language="JavaScript">

<!-- Cloak code
function leapto(form)
   {
   var site=form.go.selectedIndex;
   if (site==0)
      alert("Choose something!");
   if (site>=1)
      { location=form.go.options[site].value; }
   }
// Decloak -->
</script>


<form>
<select name="go" size="1">
<option value selected>INDEX</option>
<option value="kerbe2.htm">Biography</option>
<option value="kerbe3.htm">Projects</option>
<option value="kerbe4.htm">Quote</option>
<option value="kerbe5.htm">Portfolio</option>
<option value="kerbe6.htm">Links</option>
<option value="kerbe7.htm">Contact</option>
</select>

<br>
<br>

<input type="button" value="Visit"
            onclick="leapto(this.form)" target="Right">

</form>

Thanks!
0
Comment
Question by:kerbe
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 6
12 Comments
 
LVL 3

Accepted Solution

by:
garik earned 0 total points
ID: 1223920
To specify a target frame in a multi-frame page (constructed using FRAMESET tags), use location.href property of the corresponding frame. F.ex., if the main page contains

<FRAMESET ...>
   <FRAME NAME=Left SRC=Left.html>
   <FRAME NAME=Right SRC=Right.html>
</FRAMESET>

then you could use

if (site>=1)
 Right.location.href=form.go.options[site].value;
0
 

Author Comment

by:kerbe
ID: 1223921
Garik:

I entered the code you proposed and rewrote my <frameset> tags to your specifications (they had been <frame src="x.htm" name="right").

I now get a javascript runtime error window telling me that "Right" (in your new line of code) is undefined.

Am I missing something?
0
 
LVL 3

Expert Comment

by:garik
ID: 1223922
"Absolute" reference should help:

  top.Right.location.href=...


0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

Author Comment

by:kerbe
ID: 1223923
Aha. Ok, now the popup window tells me that " 'Right' is not an object."

Would you like to see the HTML for all the pages involved?
0
 
LVL 3

Expert Comment

by:garik
ID: 1223924
Yeah, that would be nice :)
0
 

Author Comment

by:kerbe
ID: 1223925
Okey, dokey!

****FRAME PAGE

<HTML>
<HEAD>
<TITLE>Life Upon the Wicked Stage...</TITLE>
</HEAD>
<frameset cols="20%,80%" frameborder=0 framespacing=0 border=0>
  <frame name=Left SRC="index.htm" noresize>
  <frame name=Right SRC="kerbe1.htm" noresize>
 </frameset>
<body vlink="#ff8000" link="#800080" alink="#00ff00" text="#000080" bgcolor="#ffffff">
<font face="arial,helvetica">
<bgsound src="midi/peace.mid" loop=6>

</font>
</body>
</HTML>

****INDEX PAGE

<HTML>
<HEAD>
<TITLE>INDEX</TITLE>
</HEAD>

<script language="JavaScript">

<!-- Cloak code
function leapto(form)
   {
   var site=form.go.selectedIndex;
   if (site==0)
      alert("Choose something!");
   if (site>=1)
      top.Right.location.href=form.go.options[site].value;
   }
// Decloak -->
</script>


<form target="Right">
<select name="go" size="1">
<option value selected>INDEX</option>
<option value="kerbe2.htm">Biography</option>
<option value="kerbe3.htm">Projects</option>
<option value="kerbe4.htm">Quote</option>
<option value="kerbe5.htm">Portfolio</option>
<option value="kerbe6.htm">Links</option>
<option value="kerbe7.htm">Contact</option>
</select>

<br>
<br>

<input type="button" value="Visit"
            onclick="leapto(this.form)">

</form>

<script language="JavaScript">

var scrtxt="This site is optimized for MS Internet Explorer     ...     "+
"Current Update:  July 26, 1997";
var lentxt=scrtxt.length;
var width=120;
var pos=1-width;

function scroll() {
  pos++;
  var scroller="";
  if (pos==lentxt) {
    pos=1-width;
  }
  if (pos<0) {
    for (var i=1; i<=Math.abs(pos); i++) {
      scroller=scroller+" ";}
    scroller=scroller+scrtxt.substring(0,width-i+1);
  }
  else {
    scroller=scroller+scrtxt.substring(pos,width+pos);
  }
  window.status = scroller;
  setTimeout("scroll()",50);
  }
//-->
</script>



<body vlink="#ff8000" link="#800080" alink="#00ff00" text="#000080" bgcolor="#ffffff" onLoad="scroll();return true;">

<font face="arial,helvetica">

<table>
<font size=-2><img align=left src="http://www.tcp-ip.com/scripts/count.exe?width=6&link=kerbe&style=simple&bgcolour=trans&fgcolour=000000&inc=1">
</table>
<br>
<a href="http://www.microsoft.com/ie/">
<img align=left src="art/ie_animated.gif" alt="MSIE" border=0></a>
</font>
</BODY>
</HTML>


0
 
LVL 3

Expert Comment

by:garik
ID: 1223926
I can't find the problem - it works for me in both Netscape  and MSIE (both 3.01). Do you have all the kerbe?.htm files (or at least one, kerbe1.htm)?

I've just copied your code from this page to the corresponding files, add blank kerbe1.htm, kerbe2.htm, and it works.

Although TARGET attribute in the FORM tag is extra, and the whole FORM construct belongs inside the BODY tags, it still works.

Please check file names and, perhaps,  try Netscape.
0
 

Author Comment

by:kerbe
ID: 1223927
Thanks for all your help. I've tried various permutations, loading each to my ISP and accessing them online and it always goes kahflooey -- in both MSIE and Netscape.

Maybe it's me, but no matter what I get those blasted Javascript problem windows.

:o)

Thanks for all your help.
0
 
LVL 3

Expert Comment

by:garik
ID: 1223928
Try it one more time in the morning :)
0
 

Author Comment

by:kerbe
ID: 1223929
Couldn't wait 'til morning -- And BY GOD IT WORKS!

Check it out: http://www.tcp-ip.com/kerbe

Netscape issues... animated GIFs play only once, EMBEDed midi file doesn't want to play, graphics seem to anchor wherever they choose, colors don't match. After 4 years of it, I switched to MSIE.
0
 
LVL 3

Expert Comment

by:garik
ID: 1223930
Everything seems to work fine in MSIE.
Congrats!
0
 

Author Comment

by:kerbe
ID: 1223931
That's MSIE for you -- takes a licking and keeps on ticking. Netscape, on the other hand, now refuses to play an <EMBED>ed MIDI file and runs animated GIFs only once. I'm wondering if either of these things is in conflict with Javascript...

Hardly seems likely, though. But, then again, we're talking about Netscape...

:o)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question