Ever launch a popup window and want to be able to access the information in the parent window? For example, someone types their name on your page and when they click a button you launch a pop-up window and you display their name in the pop-up.
In this example, the pop-up window reads the value of the field "parentValue" on this page and displays it in a field in the popup.
Here is all of the code used on this page, including my "Launch Popup" function.
<form name="parentForm" action="">
<input type="text" id="parentValue" value="I am the parentValue" />
<p><a href="javascript:LaunchPopup('pop-up-display-value-from-parent.aspx','400','200');">Open Popup</a></p>
</form>
<script type="text/javascript">
function LaunchPopup(page,width,height) {
OpenWin = this.open(page, "CtrlWindow", "toolbar=no,menubar=no,location=no, scrollbars=yes,resizable=yes, dependent=no,directories=no, width=" + width + ",height=" + height + ",x=50,y=50");
}
</script>
Here is all of the code in the pop-up.
<form id="form1" runat="server">
Value from the calling page: <input type="text" id="popupValue" value="" />
</form>
<script>
if (opener.document){
mother = opener.document;
document.form1.popupValue.value = mother.parentForm.parentValue.value;
}
</script>