Click to See Complete Forum and Search --> : Communicating Forms in different Windows


Attila
02-09-2003, 12:04 PM
I'm trying to make a popup to change a hidden (eventually) field in the main window.

I've got this:
The main window:
<HTML>
<HEAD>
<SCRIPT language="JavaScript" type="text/javascript">
self.name = "main"; // names current window as "main"
function showRemote()
{
var windowprops = "toolbar=0,location=0,directories=0,status=0, " + "menubar=0,scrollbars=0,resizable=0,width=150,height=200";

OpenWindow = window.open("remote.html", "remote", windowprops); // opens remote control
}
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<FORM>
<INPUT type="button" value="Open Remote Control" onClick="showRemote();">
</FORM>
<FORM action="main.php" method="POST" name="main_form" onsubmit="OpenWindow.remote_form.remote_field.value = this.main_field.value;">
<INPUT name="main_field" type="text" value=""/>
<INPUT name="Submit" type="submit" value="Submit"/>
</FORM>
</CENTER>
</BODY>
</HTML>

The popup:
<HTML>
<BODY bgcolor="#ffffcc">
Remote Control
<FORM name="remote_form" onsubmit="main.document.main_form.main_field.value = OpenWindow.remote_form.remote_field.value;">
<INPUT name="remote_field" type="text" value=""/>
<INPUT name="Submit" type="submit" value="Submit"/>
</FORM>
</BODY>
</HTML>

The example is online here:
http://www.roughdot.nl/test/JS/main.php

Javascript complains on both of the onsubmit attribs of the forms. I've made both of them interchanging (if the one is submitted, the other's field should be changed as well).
But neither is working :(

What am I doing wrong?

linnie
02-09-2003, 01:23 PM
Originally posted by Attila
...to change a hidden (eventually) field in the main window.
I don't understand your problem completely, however, I can address the part I've quoted above:

top.opener.document.formName.fieldName.value = "...";

In case some may criticize this javascript answer, I'll tell you that you can accomplish the same result by targeting your submit to the main window and use server-side code to rebuild your page with the value in the hidden field that you desire.

Lin

Attila
02-09-2003, 02:55 PM
Thx, that code works! (it's changed on the url.)

What I also want to do is do it the other way around; by submitting the form in the main page, changing the content of the textfield in the remote form.

Haven't gotten that to work yet..
*edit* HAH! Got it! *edit*

But if I were to do it as you suggest, server-side, I wouldn't be able to keep the other changes made on the main page, right?
If there are a lot of fields, and one of those needs a remote popup to be entered, it wouldn't be practical if the entire page would reload and all previously entered fields would be empty again (since the form on the main page wasn't submitted).

linnie
02-09-2003, 03:12 PM
Originally posted by Attila
But if I were to do it as you suggest, server-side...
Note: I did not say it was practical. I included that only to forestall the critics who like to frequent these forums.

However, the server-side scenario is possible by having the main page submit to the popup window so that all variables are passed, again, through a server-side process so that all the variables are saved. So when the popup submits back to the main page, those same variables are transferred back to where they were. :)

Lin