Jump to content

Pass value to parent window


robert_gsfame

Recommended Posts

How can i pass value to parent window?

 

Let say

 

page1.php

<input type="button" value="open window" onclick="javascript:window.open('page2.php')">

<div id="test"></div>

 

page2.php

<input type="button" value="close window" onclick="passvalue('HELLO WORLD')">

 

so what should be written in function passvalue() so that the words "HELLO WORLD" shown up in <div id="test"></div>??

 

what i've tried so far in confusion and not working is this

function passvalue(x)

{

window.parent.document.getElementById("test").innerHTML=x;

window.close();

}

 

thx for any help

 

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/220825-pass-value-to-parent-window/
Share on other sites

The parent window should be referred to as "opener"

  function passvalue(x)
    {
        window.opener.document.getElementById("test").innerHTML=x;
        window.close();
    }

 

Here's a working example using your code: http://www.realtown.com/test5.php

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.