...

View Full Version : controlling form foelds from previous window



bazz
04-05-2003, 05:34 PM
I got this two part script from here - http://developer.irt.org/script/165.htm

I've inserted the first bit in one of my web pages and it seems to work. Well it opens the correct form in the new window. But where do I put the second bit of the script? In the form page or as part of the script in the original page?

What tags do I put it in too?


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>




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

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



It's this last line that i dunno where to put or what tags to put it in etc.
Thanx mucho.

HairyTeeth
04-05-2003, 08:18 PM
heres a demo:

file one: the popup (save it as popup.htm)


<html>
<head>
<title>Window2</title>
</head>
<body>
<p>
Step Two:
</p>
<form name="frmPopup">
Enter First Name:
<br />
<input type="text" name="txt1" />
<br />
Enter Surname:
<br />
<input type="text" name="txt2" />
</form>
(minimise this window)
</body>
</html>


file two: the main window


<html>
<head>
<title>Main Window</title>
<script type="text/jav&#97;script" language="jav&#97;script">
<!--;
function newWindow(file,window) {
msgWindow=open(file,window,'resizable=no,width=200,height=200');
if (msgWindow.opener == null) msgWindow.opener = self;
}

//to access form contents in the popup
function accessCont(){
//var myVar = msgWindow.document.formName.formFieldName.value;
var fldOne = msgWindow.document.frmPopup.txt1.value;
var fldTwo = msgWindow.document.frmPopup.txt2.value;
alert("Field One: " + fldOne + "\nField Two: " + fldTwo)
}
//-->
</script>
</head>
<body>
<form>
Step One:
<br />
<input type="button" value="Open New Window"
onClick="newWindow('popup.htm','window2')" />
<br />
Step Three:
<br />
<input type="button" value="Access Popup Form"
onclick="accessCont()" />
</form>
</body>
</html>

bazz
04-05-2003, 11:07 PM
Thanx Hairyteeth.

I've created the two pages using copy and paste. When I click the buttons nothing happens escept that the status bar starts showing 'error on page' Have I omitted to do something?

whammy
04-05-2003, 11:12 PM
Make sure you unwrap this line:

msgWindow=open(file,window,'resizable=no,width=200
,height=200');


It should all be on one line... :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum