Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New Coder
    Join Date
    Mar 2004
    Location
    UK
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Method for referencing form data from a parent page

    On a pop up page, how do I reference a form element from the parent page, whilst at the same time being able to reference the same form element if the "popped up" page was itself a pop up from another page?

    Currently I have a form on "Page2" which opens a new window "Page3" populated by javascript based on the users selection from the form on Page2. I have previously always used the "opener" method to reference the form selection on Page2, i.e.;

    javascriptvariable = opener.abcform.xyzelement.value

    However I want to open Page3 either from Page2 directly or from [I]another page[I] (Page1) which opens Page2 as a pop up, from which the user selects as before to open Page3 as a pop up. However using the latter, the "opener" method in Page3 now doesn't work (I suspect because the "opener" method is looking for the form element in Page1 rather than Page2).
    BRUCE

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    It's confusing. Maybe it's better to post some codes.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Mar 2004
    Location
    UK
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by glenngv
    It's confusing. Maybe it's better to post some codes.
    Maybe I can pose a simpler question. I want to open a pop up window. On that pop up page, what other javascript methods than "opener"(eg "opener.abcform.xyzelement.value") can be used to reference a HTML form element on the original page?
    BRUCE

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    That's the only way. And btw, "opener" is not a method, it's an object.

    Regarding your actual problem, does the form and field names of page1 and page2 the same? If not, then you have to check if a particular field exists before accessing its value.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New Coder
    Join Date
    Mar 2004
    Location
    UK
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Regarding your actual problem, does the form and field names of page1 and page2 the same?
    No, the form only exists on page2. Therefore if I open page 2 as a pop up from page1, I'd be stuffed as regards opening page3 as a pop up from page2?
    BRUCE

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    I'm still confused. Can you explain with more details as possible. Perhaps post some related codes to make the whole picture clearer.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Regular Coder
    Join Date
    Jan 2004
    Posts
    117
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Page 1:

    Code:
    <form name="frm1">
    ...
    ...
    <input type='text' name='hello1' value=''>
    <input type='button' ... onclick='popup1();'>
    ...
    ...
    </form>
    Page 2:

    Code:
    window.opener.document.frm1.hello1.value = 'Hello World';
    
    <form name="frm2">
    ...
    ...
    <input type='text' name='hello2' value=''>
    <input type='button' ... onclick='popup2();'>
    ...
    ...
    </form>
    Page 3:

    Code:
    window.opener.document.frm2.hello2.value = 'Hello Again';
    An opener is an opener is an opener. Page 1 is the "opener" to page 2 and page 2 is the "opener" for page 3 and so on.

  • #8
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,074
    Thanks
    0
    Thanked 256 Times in 252 Posts
    But can you relate that to this question?

    Originally posted by bherrington
    However I want to open Page3 either from Page2 directly or from another page (Page1) which opens Page2 as a pop up, from which the user selects as before to open Page3 as a pop up. However using the latter, the "opener" method in Page3 now doesn't work (I suspect because the "opener" method is looking for the form element in Page1 rather than Page2).
    and to this:
    Originally posted by glenngv
    Regarding your actual problem, does the form and field names of page1 and page2 the same?
    Originally posted by bherrington
    No, the form only exists on page2. Therefore if I open page 2 as a pop up from page1, I'd be stuffed as regards opening page3 as a pop up from page2?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #9
    New Coder
    Join Date
    Mar 2004
    Location
    UK
    Posts
    28
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Actually, I stumbled across an easier solution, the reasons for which are not entirely clear to me. Provided I use a different function for opening a new window from Page1 -> Page2 as I do to open a new window from Page2 -> Page 3, this works fine, JS code in Page3 can reference a HTML form element in Page2 using "opener.". In addition, opening Page2 directly and running Page3 as a new window from it also works perfectly well. I'm not sure why the JS I was using for new windows would conflict, but it might have been the naming of Page2 as a pop up, which would still be open at the point that the call was made to open Page3 as a similar pop-up (that said, the page itself opened fine, it was just that the JS wouldn't pick up the reference to the HTML form element to create the data I wanted ).

    Fortunately I am comfortable living my life finding success accidentally without understanding every aspect of javascript at a fundamental level!!

    Thanks anyway.
    BRUCE


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •