SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to populate parent window from child window...

    hey guyz am new to this forum...i was wonderin if someone could help me with this.....can some one plz help me or point me the right direction....
    i need to know how to populate a text box in parent window using child window....i would appreciate any kinda help....plz help me with this guyz...thanx...

  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)
    Hi daraptor, Welcome to SPF!

    Parent Window
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Parent Window</title>
    <script type='text/javascript'>
    window.onload = function()
    {
      document.getElementById('f1').onsubmit = sendToChild;
      document.getElementById('b1').onclick = openChild;
    }
    function openChild()
    {
      this.disabled = true;
      xWinOpen('window_child.html');
    }
    function sendToChild()
    {
      if (xChildWindow) {
        var pta = document.getElementById('ta1');
        var cta = xChildWindow.document.getElementById('ta1');
        cta.value = pta.value;
        xChildWindow.focus();
      }
      return false;
    }
    var xChildWindow = null;
    function xWinOpen(sUrl)
    {
      // Modify 'features' to suit your needs:
      var features = "left=100,top=100,width=400,height=400,location=0,menubar=0," +
        "resizable=1,scrollbars=1,status=0,toolbar=0";
      if (xChildWindow && !xChildWindow.closed) {xChildWindow.location.href  = sUrl;}
      else {xChildWindow = window.open(sUrl, "myWinName", features);}
      xChildWindow.focus();
      return false;
    }
    </script>
    </head>
    <body>
    <h1>Parent Window</h1>
    <form id='f1'>
    <input id='b1' type='button' value='Open Child'>
    <textarea id='ta1'>parent parent parent parent</textarea>
    <input type='submit' value='Send to Child'>
    </form>
    </body>
    </html>
    Child Window
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Child Window</title>
    <script type='text/javascript'>
    window.onload = function()
    {
      document.getElementById('f1').onsubmit = sendToParent;
    }
    function sendToParent()
    {
      if (window.opener) {
        var cta = document.getElementById('ta1');
        var pta = window.opener.document.getElementById('ta1');
        pta.value = cta.value;
        window.opener.focus();
      }
      return false;
    }
    </script>
    </head>
    <body>
    <h1>Child Window</h1>
    <form id='f1'>
    <textarea id='ta1'>child child child child</textarea>
    <input type='submit' value='Send to Parent'>
    </form>
    </body>
    </html>

  3. #3
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MikeFoster View Post
    Hi daraptor, Welcome to SPF!

    Parent Window
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Parent Window</title>
    <script type='text/javascript'>
    window.onload = function()
    {
      document.getElementById('f1').onsubmit = sendToChild;
      document.getElementById('b1').onclick = openChild;
    }
    function openChild()
    {
      this.disabled = true;
      xWinOpen('window_child.html');
    }
    function sendToChild()
    {
      if (xChildWindow) {
        var pta = document.getElementById('ta1');
        var cta = xChildWindow.document.getElementById('ta1');
        cta.value = pta.value;
        xChildWindow.focus();
      }
      return false;
    }
    var xChildWindow = null;
    function xWinOpen(sUrl)
    {
      // Modify 'features' to suit your needs:
      var features = "left=100,top=100,width=400,height=400,location=0,menubar=0," +
        "resizable=1,scrollbars=1,status=0,toolbar=0";
      if (xChildWindow && !xChildWindow.closed) {xChildWindow.location.href  = sUrl;}
      else {xChildWindow = window.open(sUrl, "myWinName", features);}
      xChildWindow.focus();
      return false;
    }
    </script>
    </head>
    <body>
    <h1>Parent Window</h1>
    <form id='f1'>
    <input id='b1' type='button' value='Open Child'>
    <textarea id='ta1'>parent parent parent parent</textarea>
    <input type='submit' value='Send to Child'>
    </form>
    </body>
    </html>
    Child Window
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
    <title>Child Window</title>
    <script type='text/javascript'>
    window.onload = function()
    {
      document.getElementById('f1').onsubmit = sendToParent;
    }
    function sendToParent()
    {
      if (window.opener) {
        var cta = document.getElementById('ta1');
        var pta = window.opener.document.getElementById('ta1');
        pta.value = cta.value;
        window.opener.focus();
      }
      return false;
    }
    </script>
    </head>
    <body>
    <h1>Child Window</h1>
    <form id='f1'>
    <textarea id='ta1'>child child child child</textarea>
    <input type='submit' value='Send to Parent'>
    </form>
    </body>
    </html>
    hey mike thanx for replyin...what i need exactly is....i have a parent window with a text box and a search hypertext link......so when i hit the search hypertext link...it opens a popup window which is the child window....ok...in that child windowi searchd something and i got results....now....when i click one of the results in the child window...it should go and populate the parent window text box.....u know what i mean....

  4. #4
    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)
    Yes, I know what you mean.

    The demo I posted shows how to move the contents of a <textarea> (but could just as well be an <input>) from a child window to the parent window. It also shows how to move the contents from the parent window to the child window.

    The demo illustrates a technique you can adapt to your own page. Is that not what you wanted?

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by MikeFoster View Post
    Yes, I know what you mean.

    The demo I posted shows how to move the contents of a <textarea> (but could just as well be an <input>) from a child window to the parent window. It also shows how to move the contents from the parent window to the child window.

    The demo illustrates a technique you can adapt to your own page. Is that not what you wanted?
    i wanted to move text from child to window....so you say i continue addin that code in my parent and child windows...?????

  6. #6
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mike has provided you a very complete example based on his wonderful x-system. It might be a little daunting at first though


    Quicker 'n' dirtier:

    a link in your popup window:
    <a href="http://www.sitepoint.com" onclick="opener.doSomething(this.href);return false;">Sitepoint</a>

    then in your main window have
    function doSomething(linkClicked) {
    alert(linkClicked);
    }

  7. #7
    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's a self-contained demo - no other files are needed.

    But Jim's example is alot quicker

    Just copy Jim's code per his instructions and that should give you some ideas.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2007
    Posts
    26
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by jimfraser View Post
    Mike has provided you a very complete example based on his wonderful x-system. It might be a little daunting at first though


    Quicker 'n' dirtier:

    a link in your popup window:
    <a href="http://www.sitepoint.com" onclick="opener.doSomething(this.href);return false;">Sitepoint</a>

    then in your main window have
    function doSomething(linkClicked) {
    alert(linkClicked);
    }
    hey jim.....am a newbie man...so plz bear with me....waht i want is...in the parent window..there is a href with a textbox....that href is child window...so when i click the href....it should open child window....and in the child window....i will do a search and get a result....then that result when i click there it should come and populate the parent window....for example...check this site....sidestep.com .......in this click on airport code..it will opena popup..in the popup search for some airport code and hit search....it will display a result...then when u click on the required code....it will close and populate the parent window with the code u searchd....i wanna know how to do that exactly........plz plz plz help me with this.....thanx

  9. #9
    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)
    ...
    Last edited by MikeFoster; Feb 5, 2007 at 12:16. Reason: Nevermind. OP started another thread on same topic.


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
  •