View Full Version : Send data to opener document

01-31-2007, 03:17 PM
I'll make it simple.
I have a popup and a form in it. The form is being generated with PHP.

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

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.

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

This is the JS function I wrote:

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?

01-31-2007, 03:40 PM
Changed the function to:

function SendToOpener(fieldname) {
if (window.opener && !window.opener.closed) {
window.opener.document.OpenerForm.openerformfield.value = fieldname;

and it works now.