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 2 of 2
  1. #1
    Regular Coder
    Join Date
    Jan 2006
    Posts
    377
    Thanks
    8
    Thanked 1 Time in 1 Post

    Send data to opener document

    I'll make it simple.
    I have a popup and a form in it. The form is being generated with PHP.

    Code:
    <form name="PopupForm">
    <input type="text" name="gk1154567" value="gk1154567" readonly>
    <input type="button" value="Send" onClick="javascript:SendToOpener('gk1154567');">
    </form>

    When clicked on Send, I want the gk1154567 (which is both the name and the value of the text field) to be sent to a field in a form in the opener document.

    Code:
    <form name="OpenerForm">
    <input type="text" name="openerformfield">
    <input type="submit" value="Submit">
    </form>

    This is the JS function I wrote:

    Code:
    function SendToOpener(fieldname) {
    	opener.document.OpenerForm.openerformfield.value = document.PopupForm.fieldname.value;
    }
    When I load the page and click the button, I get this error in JavaScript Console:

    Error: localForm.fieldname has no properties

    Any ideas what I am doing wrong?

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Posts
    377
    Thanks
    8
    Thanked 1 Time in 1 Post
    Changed the function to:

    Code:
    function SendToOpener(fieldname) {
    	if (window.opener && !window.opener.closed) {
    		window.opener.document.OpenerForm.openerformfield.value = fieldname;
    		window.close();
    	}
    }
    and it works now.


  •  

    Posting Permissions

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