Multiple targets using one href using iframes in javascript example

I have a frame_index.cfm page that defines 8 separate frames displayed on one page.  With these 8 frames open, I'm trying to go from Frame1 with an <href .. to populate iframe2 and iframe3.  Presently I go from Frame1 to Frame2 as follows,

<a href="../frame2.cfm?jobnum=#jobnum#" target="iframe2">#jobnum#</a>


Once Frame2 is populated I select another <href to populate Frame3 as follows,

<a href="../frame3.cfm?jobnum=#jobnum#" target="iframe3">#jobnum#</a>

The targets, "iframe2" and "iframe3" are used to go through the frame_index.cfm page below.

.
.
.
<td><iframe name=iframe2 src="http://IP/frame2.cfm" width="425"  height="250">                     </iframe></td>
     <td><iframe name=iframe3 src="http://IP/frame3.cfm" width="475" height="250"></iframe></td>
.
.
.

I tried to use the following javascript example, and it almost works for my application. I'm sure how to incorporate the target names to this javascript example.


<SCRIPT language="JavaScript">
function change2()
{
  parent.iframe2.location="http://IPaddress/frame_index.cfm";
  parent.iframe3.location="http://IPaddress/frame_index.cfm";
}
</SCRIPT>

<A HREF="javascript:change2('#jobnum#');">#jobnum#</A>


This kind of works except the entire page of 8 frames opens up in frame2 and frame3 instead of just those frame2.cfm and frame3.cfm pages by themselves.  So it looks like the entire frame_index.cfm page is called instead of each frame going to their individual targets
<iframe name=iframe2 and <iframe name=iframe3.
talahiAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
Michel PlungjanConnect With a Mentor IT ExpertCommented:
<a href="../frame2.cfm?jobnum=#jobnum#"
onClick="window.frames['frame3'].location='../frame3.cfm?jobnum=#jobnum#';"
target="iframe2">#jobnum#</a>
0
 
Michel PlungjanIT ExpertCommented:
If the page for frame 2  is
../frame2.cfm?jobnum=#jobnum#

how can you expect
http://IPaddress/frame_index.cfm

to be what you want?

If you only want ONE cfm, then pass the frame number and handle it in the cf

http://IPaddress/frame_index.cfm?frame=2&jobnum=#jobnum#

Like this

<SCRIPT language="JavaScript">
function changeAll(jobnum) {
  for (var i=1;i<=8;i++) window.frames["iframe"+i].location="http://IPaddress/frame_index.cfm?frame="+i+"&jobnum="+jobnum;
}
</SCRIPT>
 
<A HREF="#" onClick=changeAll('#jobnum#'); return false">#jobnum#</A>

Open in new window

0
 
talahiAuthor Commented:
I want to populate 2 distinct frames ("http://IP/frame2.cfm and "http://IP/frame3.cfm) with the selection of 1 href selection.  Within the http://IP/frame_index.cfm page are 2 target names, (iframe2 and iframe3 below)

frame_index.cfm page
.
.
<td><iframe name=iframe2 src="http://IP/frame2.cfm" width="425"  height="250">                     </iframe></td>
     <td><iframe name=iframe3 src="http://IP/frame3.cfm" width="475" height="250"></iframe></td>
.
.
.
where I want the href selection to be directed.  Right now I can do the following,

<a href="../frame2.cfm?jobnum=#jobnum#" target="iframe2">#jobnum#</a>  This href selection will populate the frame2.cfm page with a new jobnum.  The problem is I want this one href selection to populate both frame2.cfm and frame3.cfm with one click.  I believe the JS is the way to do it but I do not know the proper way to script this function.  Like I said what I have kind of works but it seems to ignore the Target or Frame names (iframe2, iframes3)  and replicates ALL 8 frames within the frame2.cfm and frame3.cfm pages.

 
0
 
talahiAuthor Commented:
Thanks, it works with the following modifications, changing 'window' to 'parent' and adding  target="iframe2" to href.

<a href="../frame2.cfm?jobnum=#jobnum#" target="iframe2"
onClick="parent.frames['iframe3'].location='../frame3.cfm?jobnum=#jobnum#';"
target="iframe3">#jobnum#</a>
0
 
Michel PlungjanIT ExpertCommented:
No. You cannot have two targets

My code had target="frame2" too

<a href="../frame2.cfm?jobnum=#jobnum#"
onClick="window.frames['frame3'].location='../frame3.cfm?jobnum=#jobnum#';"
target="iframe2">#jobnum#</a>

And window.frames should have worked the same as parent.frames
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.