3 Replies - 5603 Views - Last Post: 28 January 2013 - 09:02 AM

#1 wama_mms  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 54
  • Joined: 06-May 12

get data from child window to the parent

Posted 27 January 2013 - 07:41 PM

i have a question about how to get data from child window to parent window i am using javascript and the data with PHP
i have 2 pages the first one called : index.php with the following code
 <!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Proj</title>
        <script type="text/javascript">
            function openWindow() {
                window.open("popup.php", "popup_id", "scrollbars=no,resizable,width=200,,left=300,top=300,height=200");
            }
        </script>
    </head>
    <body>
        <form name="form1" action="">
            <input name="initialdata" type="text" value="initial data" />
            <input type="button" value="Send" onclick="openWindow()" />
        </form>
    </body>
</html>


and the child one : popup.php
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>popup</title>
        <script type="text/javascript">
            function putData() {
                //How to copy from that file -> document.formname.popupdata.value to 
                //index.php -> document.form1.initialdata.value???
                window.close();
            }
            function loadData() {
                window.opener.document.getElementsByName("initialdata")[0].value;
            }
        </script>
    </head>
    <body onload="loadData();">
        <form name="formname" action="">
            <input name="popupdata" type="text" value="" />
            <input type="button" value="Send" onclick="putData()" />
        </form>
    </body>
</html>



Is This A Good Question/Topic? 0
  • +

Replies To: get data from child window to the parent

#2 CTphpnwb  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 3034
  • Posts: 10,588
  • Joined: 08-August 08

Re: get data from child window to the parent

Posted 27 January 2013 - 08:32 PM

PHP is server side. It has nothing to do with browser windows. Moving to Javascript.
Was This Post Helpful? 0
  • +
  • -

#3 andrewsw  Icon User is online

  • It's just been revoked!
  • member icon

Reputation: 3615
  • View blog
  • Posts: 12,441
  • Joined: 12-December 12

Re: get data from child window to the parent

Posted 27 January 2013 - 08:35 PM

// give your popupdata-input an id:
document.getElementById("popupdataid").value = window.opener.document.getElementsByName("initialdata")[0].value;


In fact, give "initialdata" in the main page an id as well - after all, there is only one of them.

This post has been edited by andrewsw: 27 January 2013 - 08:36 PM

Was This Post Helpful? 0
  • +
  • -

#4 wama_mms  Icon User is offline

  • D.I.C Head

Reputation: -1
  • View blog
  • Posts: 54
  • Joined: 06-May 12

Re: get data from child window to the parent

Posted 28 January 2013 - 09:02 AM

View Postandrewsw, on 27 January 2013 - 08:35 PM, said:

// give your popupdata-input an id:
document.getElementById("popupdataid").value = window.opener.document.getElementsByName("initialdata")[0].value;


In fact, give "initialdata" in the main page an id as well - after all, there is only one of them.

thanks it works now :) thanks for your help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1