windows / DOM referencing problems... please help...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reply Via Newsgroup

    #1

    windows / DOM referencing problems... please help...


    Folks,

    Windows, and refering to them (be they in seperate frames or in a popup)
    always catch me... There is parent, top, self, the name of the window
    itself and where it sits when refering to its full property name... It
    drives me up the wall that I can't get this right after six months or so...

    Before someone gives me a spiel on not using popups:

    1) It is for an intranet LAMP based application and
    2) Popups are not automatic but instead requested
    via a properly labeled button/link
    3) My end user environment permits popups from my domain.

    The question in short format:
    How can a child window call a function that exists in a parent window to
    read values from the child window and copy to the parent?

    Longer question with more meat on the bones:
    Two windows - one we call father (the parent) and the popup we'll call kid.

    I have a value that is selected in the kid window that needs copying to
    the parent/father window.

    This is easy enough if the javascript is contained in the child/kid
    window but not if my javascript is called from the parent window.

    I know for example, I can have a function in the father/parent window
    called testone(). I know the child can call this function using
    window.opener.t estone(); but how do I have this function refer to a
    field in the kid/child window?

    Roughly speaking, I've tried the following:

    parent/father window contains following script:

    function testone()
    { alert(kid.docum ent.formName.fi eldname.value);
    return true;
    }


    child/kid window has the following onClick event on the submit button
    onClick="return window.opener.t estone();"

    If my 'alert()' function call in test one is set to "hello" - it works -
    but if I ask it to give me tthe value of a form field in the popup
    window called formFieldname - it tells me that
    kid.document.fo rmName.fieldnam e.value has no properties...

    I believe the problem I am having is beacuse the script sits in the
    parent window and its being called from the child - and I'm muddling up
    the window references on how one see's the other.

    Can someone help me? All help, via the newsgroup is much appreciated.

    Thanks
    Randell D.
  • Michael Winter

    #2
    Re: windows / DOM referencing problems... please help...

    On Sun, 18 Apr 2004 01:39:40 GMT, Reply Via Newsgroup
    <reply-to-newsgroup@pleas e.com> wrote:

    [snip]
    [color=blue]
    > If my 'alert()' function call in test one is set to "hello" - it works -
    > but if I ask it to give me tthe value of a form field in the popup
    > window called formFieldname - it tells me that
    > kid.document.fo rmName.fieldnam e.value has no properties...[/color]

    Have you actually determined which object is undefined (if it's not
    explicitly stated in the message)? That is, have you tried

    alert( kid );

    then

    alert( kid.document );

    and so on until you get "undefined" displayed?
    [color=blue]
    > I believe the problem I am having is beacuse the script sits in the
    > parent window and its being called from the child - and I'm muddling up
    > the window references on how one see's the other.[/color]

    I would think that the simplest solution would be to pass references to
    the function during the call, then it wouldn't matter where the elements
    are located. For example:

    <button type="submit" onclick="return opener.testone( this.form)"[color=blue]
    >Submit</button>[/color]

    function testone( form ) {
    alert( form.fieldname. value );
    // ...
    }

    Of course, this depends on the functions you're designing, what data
    they're accessing, and the architecture of the site.

    Good luck,
    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • Reply Via Newsgroup

      #3
      Re: windows / DOM referencing problems... please help...

      Michael Winter wrote:[color=blue]
      > On Sun, 18 Apr 2004 01:39:40 GMT, Reply Via Newsgroup
      > <reply-to-newsgroup@pleas e.com> wrote:
      >
      > [snip]
      >[color=green]
      >> If my 'alert()' function call in test one is set to "hello" - it works
      >> - but if I ask it to give me tthe value of a form field in the popup
      >> window called formFieldname - it tells me that
      >> kid.document.fo rmName.fieldnam e.value has no properties...[/color]
      >
      >
      > Have you actually determined which object is undefined (if it's not
      > explicitly stated in the message)? That is, have you tried
      >
      > alert( kid );
      >
      > then
      >
      > alert( kid.document );
      >
      > and so on until you get "undefined" displayed?
      >[color=green]
      >> I believe the problem I am having is beacuse the script sits in the
      >> parent window and its being called from the child - and I'm muddling
      >> up the window references on how one see's the other.[/color]
      >
      >
      > I would think that the simplest solution would be to pass references to
      > the function during the call, then it wouldn't matter where the elements
      > are located. For example:
      >
      > <button type="submit" onclick="return opener.testone( this.form)"[color=green]
      > >Submit</button>[/color]
      >
      > function testone( form ) {
      > alert( form.fieldname. value );
      > // ...
      > }
      >
      > Of course, this depends on the functions you're designing, what data
      > they're accessing, and the architecture of the site.
      >
      > Good luck,
      > Mike
      >[/color]

      Thanks... I am using Mozilla and its javascript debugger didn't give me
      enough to go on... However I'll try 'walking' true the object like you
      suggested... My alternative solution is to have the child/kid window
      have the script inline (as opposed to calling it from the parent/father
      window). Its a short small script...

      As always though, thanks for your help,
      randell d.

      Comment

      Working...