Solved

Multiple targets using one href using iframes in javascript example

Posted on 2008-10-15
5
330 Views
Last Modified: 2013-11-11
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.
0
Comment
Question by:talahi
  • 3
  • 2
5 Comments
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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
 

Author Comment

by:talahi
Comment Utility
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
 
LVL 75

Accepted Solution

by:
Michel Plungjan earned 150 total points
Comment Utility
<a href="../frame2.cfm?jobnum=#jobnum#"
onClick="window.frames['frame3'].location='../frame3.cfm?jobnum=#jobnum#';"
target="iframe2">#jobnum#</a>
0
 

Author Comment

by:talahi
Comment Utility
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
 
LVL 75

Expert Comment

by:Michel Plungjan
Comment Utility
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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

762 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

8 Experts available now in Live!

Get 1:1 Help Now