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 10 of 10
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Confused about "OPENER" passing data to parent from child

    Hello fellow codingForums members.

    I've read and read, tried and tried different functions that you have listed to solve other member's problems and can't get any of them to work.

    I have created two HTML pages to test these functions that send data from the child window to the parent window.

    For real what I want to happen is that the user will click on a link to open up an amedities page and select what they want. Then to have those amedities selected by checkboxes to be sent to the parent page so that it can be submitted to the search engine along with dates & location with the click of the search button.

    you would click on "Link" to open the pop-up. then type info into the textbox. Click on "Close" to have the data sent to the mainForm's textbox.. I'm not worried about the pop-up closing that will be after I solve this.

    This is what I have.

    TEST1.htm

    <body>
    <form name="mainForm" method="post" action="">
    Text from Pop-up<br>
    <input type="text" name="mainText">
    <a href="javascriptpenWindow();">Link</a>
    </form>
    <script language="JavaScript" type="text/javascript">
    function openWindow()
    {
    window.open("test2.htm", "test2Window", "width=400", "height = 400");
    }
    </script>
    </body>

    Test2.htm

    <body>
    <form name="popForm" method="post" action="">
    Enter Text<br>
    <input type="text" name="popText">
    <a href="javascript:sendBack();">Close</a>
    </form>
    <script language="JavaScript" type="text/javascript">
    function sendBack()
    {
    opener.document.mainForm.mainText.text = document.popForm.popText.value;
    }
    </script>
    </body>

    Thanks,
    Hogtied

    ps: for some reason codingForums modifies the code typed. Maybe in conflict with what they have coded. I would have included the files but can't seem to figure out how.. Now upload button.....
    Last edited by hogtied; 12-15-2002 at 02:28 AM.

  • #2
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Oops...sending it to the wrong form:

    opener.document.mainForm.mainText.value = document.popForm.popText.value;

    Also: window.open("test2.htm", "test2Window", "width=400,height=400");

    [all one argument, no spaces]

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by cheesebagpipe
    Oops...sending it to the wrong form:

    opener.document.mainForm.mainText.value = document.popForm.popText.value;

    Also: window.open("test2.htm", "test2Window", "width=400,height=400");

    [all one argument, no spaces]


    Thanks. actually that was a typo i made here, writing the post.. sry.. and for the "width=400,height=400" being one argument didn't seem to make a difference. I am thankful for you reply
    Last edited by hogtied; 12-15-2002 at 02:34 AM.

  • #4
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Are we done now? eesh....

    <html>
    <head>
    </head>
    <body>
    <script language="JavaScript" type="text/javascript">
    function openWindow()
    {
    window.open('test2.htm','test2Window','width=300,height=200,left=200,top=200,status=0');
    }
    </script>
    <form name="mainForm" method="post" action="">
    Text from Pop-up<br>
    <input type="text" name="mainText"><br>
    Checkbox from Pop-up<br>
    <input type="checkbox" name="mainBox"><br><br>
    <input type="button" value="NEXT" onclick="openWindow()">
    </form>
    </body>
    </html>

    [test2.htm]

    <html>
    <head>
    </head>
    <body>
    <script language="JavaScript" type="text/javascript">
    function sendBack()
    {
    if (opener && !opener.closed) //make sure main window is there
    {
    var mainForm = opener.document.mainForm; //save typing!
    /* two simple assignments */
    /* move data from here to there */
    mainForm.mainText.value = document.popForm.popText.value;
    mainForm.mainBox.checked = document.popForm.popBox.checked;
    }
    }
    </script>
    <form name="popForm" method="post" action="" onsubmit="sendBack();self.close()">
    Enter Text<br>
    <input type="text" name="popText"><br>
    Check Checkbox<br>
    <input type="checkbox" name="popBox"><br><br>
    <input type="submit" value="NEXT">
    </form>
    </body>
    </html>

    Hitting the submit button calls the onsubmit handler - which calls the sendBack function; when it returns, it closes the window.
    Last edited by cheesebagpipe; 12-15-2002 at 07:05 AM.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Originally posted by cheesebagpipe
    Are we done now? eesh....
    Ya yah.. i know I can be a pain sometimes

    That code works and I THINK I understand the logic behind it. I was reading these posts and trying it out, reading some more and trying it out. Couldn't figure what I was doing wrong. Then again I still don't understand it. But In search for my answer by reading alot of these posts, I noticed that you had relpied to a lot of them. Thanks for helping these people and myself.

    Thanks.
    hogtied

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Wow - that's a very thoughtful thing to say. Thanks. I was pulling your leg a bit; you were editing your posts even as I was typing in an answer - believe me, you're not the first - so I kept thinking I was looking at the wrong thread. Very entertaining.

    Tossed in some commenting to help (above). You can write a routine that does this automatically - hint: it involves naming the fields in each page the same - but, I'll leave that for you to work out. Don't worry - with your attitude, you'll never have a problem getting help around here.

    cya, pipe

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yet another question about this post.....

    I have checkboxes that has spaces within their "name" attributes.

    (i.e. <input name="AMENITY_Pets Allowed type="checkbox">)

    the above form object can't be changed.

    All the other ones without spaces work. and obviously the ones with don't..

    Might you know of a way to still have the variables sent to the main page even thou the "name" attribute has spaces?

    Thanks again
    hogtied.

  • #8
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    n.p. -

    mainForm['AMENITY_Pets Allowed'].checked =
    document.popForm['AMENITY_Pets Allowed'].checked;

    Just use it as a string, in square brackets. Watch the dots.

    One other thing: this forum butchers window.open code, so be careful to remove all whitespace, and put the line that actually calls .open() on one line, with no breaks.

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks,, your awesome

    Just don't quit your day job to help us out hehe..

    you and beetle seem to live on this forum...

    as for the automatic thing you stated above... I think you would name the fields the same on both HTML files. then have an "onChange" call a function on the parent window to update the field's value.. Am I heading in the right direction??

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Location
    Souteast Coast
    Posts
    124
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Another question. How do you send specific form objects instead of sending everything.

    Say you had 5 form objects and the user only selects 3 of them. What I'm looking to do is just send the information on those 3, not all 5. I have a total of 30 objects and want to limit what gets sent by what the user selects.

    Is there a way to do this??

    On the other hand I'm still trying to understand how you did the automatic update of the different form objects. What is the "el" varible?

    Let me tell I would rather do the automatic than the way I have it now.. I had to do an "IF" statement for every object of whether to send the value or not.. otherwise whether I selected it or not it would transfer the information to the parent window, and use it for the search critera. The pages with code you sent me works great but I'm transferring checkboxes to hidden objects.

    Well Thanks again.
    Hogtied......


  •  

    Posting Permissions

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