Solved

Java Programming question

Posted on 1997-07-28
12
178 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
  • 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
 

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

947 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now