[thelist] JAVASCRIPT and IFRAMEs

.jeff jeff at members.evolt.org
Mon Jul 29 16:01:01 CDT 2002


phil,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Phil Essing
>
[...] on my main HTML page I have an IFRAME that loads
> another HTML document.  Within this second document
> (contained in the IFRAME) I have an SSI which contains
> a form.  In this form there is a link which opens a
> popup calendar, with each date hyperlinked.  When the
> user clicks a date, the value needs to be passed to the
> appropriate form fields.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

sounds easy enough.  if you're not checking for the opener from the document in the iframe at the time of creation of the popup, you should be and if it doesn't exist setting it to self.

if(!popupWin.opener)
  popupWin.opener = self;

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> Trying to pass the values back to the form will not work
> using <a href="#" onClick="self.opener.document.formname
>.fieldname.value">day</a>.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

first of all, fix the way you're using the <a> tag.  do *not* use a hash (#) as the value of the href attribute.

Links & JavaScript Living Together in Harmony
http://evolt.org/article/thelist/17/20938/

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> The code works outside of the IFRAME, because
> self.opener is apparent.  Within the IFRAME, however,
> I get the following error: "self.opener.document.
> formname.fieldname.value" is not an object.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

no matter if the window was opened from a document at the top level, from a document in an iframe, or from a document in a frameset, the opener should *always* be apparent to the popup.  if i were you i'd consider working out where the object reference breaks.

try alerting each step of the way:

alert(self.opener);
alert(self.opener.location.href);
alert(self.opener.document);
alert(self.opener.document.forms.length);
alert(self.opener.document.formname);
alert(self.opener.document.formname.elements.length);
alert(self.opener.document.formname.fieldname);
alert(self.opener.document.formname.fieldname.value);

if you could make this available online somewhere it'd be easier to debug.

thanks,

.jeff

http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/




More information about the thelist mailing list