View Full Version : Child parent div style change problem

Feb 27th, 2008, 07:13 AM

I have a parent page that opens a child page. In the child page I have a button that a user would click on that would change the div in the parent from display "none" to display "block".

My problem is the button onclick event in the child page. How do I make it change the div style in the parent?

My code so far...

Child page button code

<input type="button" value="OK" onClick="changeDisplay('div1','block');self.close()">

In the parent page I have the following script that hides content using a div

function changeDisplay(elem,displayMode){
document.getElementById(elem).style.display = displayMode;

In the body of the parent I use this

<div id="div1" style="display: none">Text to display when child page "OK" button clicked</div>

I open the child popup using this

<input type="button" value="View" onClick="openMyPage();">"

function openMyPage() {
if (!myPage || myPage.closed)
myPage = window.open('child.php');
alert("The page is already open but minimized");

Feb 27th, 2008, 10:05 AM
the pop up is a new window, thus you need another Global Object to reach the parent, which is, in javascript, exactly the parent reference: