SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Sep 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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();

    }
    }

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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:
    Code:
    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);
      }
    }

  3. #3
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    Kirtan


Bookmarks

Posting Permissions

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