Home Articles FAQs XREF Games Software Instant Books About Feedback Search Site-Map
irt.org logo

Q165 How do I access variable values and form field values across windows?

irt.org | Knowledge Base | JavaScript | Form 3.1 | Q165 [ previous next ]

Q165 How do I access variable values and form field values across windows?

If one window opens another:

<script language="JavaScript"><!--
function newWindow(file,window) {
    msgWindow=open(file,window,'resizable=no,width=200,height=200');
    if (msgWindow.opener == null) msgWindow.opener = self;
}
//--></script>

<form>
<input type="button" value="Open New Window" onClick="newWindow('a.html','window2')">
</form>

Then to access a variable in the new window from the original window:

var myVar = msgWindow.myVar;

To access a variable in the original window from the new window:

var myVar = opener.myVar;

To access the contents of a form field in new window from the original window:

var myVar = msgWindow.document.formName.formFieldName.value;

To access the contents of a form field in the original window from the new window:

var myVar = opener.document.formName.formFieldName.value;

To access the contents of a form field in the original window from a frame in the new window:

var myVar = top.opener.document.formName.formFieldName.value;

Feedback on 'Q165 How do I access variable values and form field values across windows?'


Provide feedback ...
AddThis Social Bookmark Button

Provide feedback ... AddThis Social Bookmark Button


Last Updated: 30th March 2008. Maintained by: Martin Webb and Michel Plungjan
irt.org liability, trademark, document use, privacy statement and software licensing rules apply.
Copyright © 1996-2008 irt.org, All Rights Reserved.