Passing data from parent to child window

Hi all,
I am new to Javascript,I am trying to pass user data from a parent window to a child window. I read somewhere that if i want to pass data as soon as child window opens i need to add a pause for the form elements to load. I am using the code snippet below.objf.form_parent.text1 is a text field in the parent window and newWindow.document.test.text1. is a field in child window. Can anyone help what I am doing wrong.
Thanks,
Pavan

function newWindow(){

   var newWindow;
   if(!newWindow||newWindow.closed){
    newWindow =

window.open(‘popup’,‘addwin’,‘width=500,height=250,status=yes,scrollbars=yes,resizable=yes’);
var tmp=newWindow.document;
setTimeout('newWindow.document.test.text1.value= ‘objf.form_parent.text1.value’,50);

   tmp.close();

                                   }

}

It might be easier for Javascript to run onload in the child window, and then get the data from the parent window. But that might not always be possible, so you can try something like this:


var newWin = null; // global

function newWindow()
{
  if (!newWin || newWin.closed) {
    newWin = window.open('popup','addwin','width=500,height=250,status=yes,scrollbars=yes,resizable=yes');
    waitForWin();
  }
}

function waitForWin()
{
  if (newWin.document && newWin.document.forms && newWin.document.forms['childWinForm']) {
    newWin.document.forms['childWinForm'].text1.value = document.forms['parentWinForm'].text1.value;
  }
  else {
    setTimeout(waitForWin, 250);
  }
}

I think there is no need to use “setTimeout”
you can always retrieve data from parent window using this statement
“opener.document.getElementById(‘id’)”
Hope this helps :slight_smile: