Results 1 to 2 of 2

Thread: Setting values of parent window to the child window

  1. #1
    Join Date
    Jun 2008

    Setting values of parent window to the child window

    Hi all,

    I have a parent window with a text box and a button. On clicking the button, I am opening a child window by using window.open(). The child window has a textbox.

    I am trying to set the value of the parent window text box to the child window text box. When i was just searching, i got the following code snippet:

    var newWin = window.open( ... );
    newWin.document.forms[0].fieldname.value = "new value";

    But this does not work for me.

    I have seen many examples in which the values can be passed from the child window to the parent window using the 'opener.document.....' method. But i am uncertain about passing the values of parent window to child window. Can anyone help me?

  2. #2
    Join Date
    Feb 2003
    Michigan, USA
    You example code looks correct, and should work as long as the window you open is in the same domain as the window that opened it. If not, the JavaScript interpreter will block all script access between the two windows.

    Looking at it again though, you might be trying to set the text field value before the text field is available in the DOM. You'll probably need to wait for the new window's onload event before setting the text field value.
    var newWin = window.open( ... );
    newWin.onload = function() {
      document.forms[0].fieldname.value = "new value";

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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