[Javascript] Tricky frame problem.
Rick Holcomb
rholcomb at holc.biz
Thu Jan 26 10:11:31 CST 2006
Roger,
Thanks. Your definition of parent and top helped me figure out where
I was going wrong. I was using top to identify the left frame but once I
added the additional top level frame now top referenced it. I changed the
script from top.frames['leftFrame'].document.theForm.txtBucket to
frames['leftFrame'].document.theForm.txtBucket and everything is working
great.
Rick
-----Original Message-----
From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu]
On Behalf Of Roger Roelofs
Sent: Thursday, January 26, 2006 4:22 AM
To: [JavaScript List]
Subject: Re: [Javascript] Tricky frame problem.
Rick,
On Jan 25, 2006, at 11:31 PM, Rick Holcomb wrote:
> I have a frameset that contains two frames a top and a main frame.
> I use the top as a menu and load all the pages into the main frame.
> My problem is that I have designed a new page that contains frames
> itself.
> The frames in the new page are topFrame, leftFrame and mainFrame.
> When I post values from mainFrame to leftFrame using a script in
> topFrame,
> everything works fine. But once I add this frameset to the first
> frameset
> all hell brakes loose. So main will now conatin topFrame, leftFrame and
> mainFrame.
>
> The javascript call I make from mainFrame to topFrame is:
>
> parent.passText2('value')
>
> The script in topFrame that posts the value to leftFrame is:
>
> function passText2(str) {
> if (top.frames['leftFrame'].document.theForm.txtBucket.value == "")
> {
> top.frames['leftFrame'].document.theForm.txtBucket.value =
> top.frames['leftFrame'].document.theForm.txtBucket.value + str;
> }
> else
> {
> top.frames['leftFrame'].document.theForm.txtBucket.value =
> top.frames['leftFrame'].document.theForm.txtBucket.value + "," + str;
> }
> }
Is there any chance of putting up a demo page for us? The frame names
are kind of generic so I'm having a little trouble following the flow
of your description. Here are some general comments that might point
you in the right direction.
The javascript needs to know about the frame hierarchy. Also, keep in
mind that the javascript function runs in the context in which it was
declared, not from where it is called. I haven't done this kind of
cross-frame call in years, but I recall that it was often most useful
to link the script into the frameset document. Calling a script linked
into the frameset from a child frame becomes parent.theFunction(). If
the javascript lives in another of the child frames, then you call it
as parnet.frames['topframe'].theFunction()
The difference between 'parent' and 'top' is that 'top' points to the
topmost frameset while 'parent' only goes up one level.
You can save yourself a lot of typing by putting an object reference
into a variable like so...
function passText2(str) {
var dest = parent.frames['leftFrame'].document.theForm.txtBucket;
if ( dest.value == "" ) dest.value = str;
else dest.value += "," + str;
}
I use firefox for all my javascript development simply because the
debugging tools are far superior. Using the javascript console and DOM
inspector can save you hours if not days.
hth
--
Roger Roelofs
Datacomp Appraisal Services
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript
More information about the Javascript
mailing list