Solved

Multiple targets using one href using iframes in javascript example

Posted on 2008-10-15
5
334 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
ID: 22728883
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
ID: 22730756
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
ID: 22731087
<a href="../frame2.cfm?jobnum=#jobnum#"
onClick="window.frames['frame3'].location='../frame3.cfm?jobnum=#jobnum#';"
target="iframe2">#jobnum#</a>
0
 

Author Comment

by:talahi
ID: 22732006
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
ID: 22732787
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

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

The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

896 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

13 Experts available now in Live!

Get 1:1 Help Now