PDA

View Full Version : DHTML Between Child Window and Parent Window


Freed
07-16-2002, 05:11 PM
I was wondering how to change text in a parent window depending on what was selected in a child window. For example, say a parent window is displaying "xyz" and there is a pop-up window for changing this value to either "abc" or "qrs". How would you change the displayed "xyz" to which ever option was picked in the child window (pop-up)?

Freed

ShriekForth
07-16-2002, 05:52 PM
Have the child window reference the parent/opener window using opener. So if you had a drop down list in the child have something trigger a script on the child to write that value back to the parent. A hidden form field, or a function in the parents like this ...

CHILD
function sendColor(){
opener.writeColor(document.childForm.colors[document.childForm.colors.selectedIndex].value);
}
<form name="childForm">
<select name=colors>
<option value="Orange">Orange
<option value="Black">Black
<option value="Blue">Blue
</select>
<a href="javascript:sendColor()">Color</a>
</form>

on submit or on change call sendColor(), it will call the parent function write color

PARENT

function writeColor(newColor){
document.body.style.color = newColor;
}

in this case the color would be passed and the text of the document would change color.

ShriekForth