Sending form info from popup window to original window

P

Person

I have a popup window with a form:

The popup window is opened like this:

<SCRIPT LANGUAGE=javascript>
window.open('primos.html', 'primos', config='height=300, width=400')
</SCRIPT>

The form on the popup window is this:

<form action="primos.php" method="POST">
Buscar los primos entre 1 y
<input type="text" size="7" name="max" value="1000"><br>
<input type="submit" name="start" value="Start">
</form>

How can I get the form to send the info to "primos.php" and open it in
the original window?

Thanks in advance,
Philippe
 
L

Lasse Reichstein Nielsen

I have a popup window with a form:

The popup window is opened like this:

<SCRIPT LANGUAGE=javascript>

The "type" attribute is required. This should be
window.open('primos.html', 'primos', config='height=300, width=400')

The "config=" is not necessary. The config string should not contain spaces,
some browsers choke on them.
</SCRIPT>

The form on the popup window is this:

<form action="primos.php" method="POST"> ....
How can I get the form to send the info to "primos.php" and open it in
the original window?

How do you know that the original window is still open?

If it is open, you can use the target attribute on the form tag to send
the result to that window. This requires you to know the name, if any,
of the original window.

There is a way to find this name (or set it, if there is no name)
dynamically:

<form action="primos.php" method="POST" target="_blank"
onsubmit="if (!opener.closed) {
if (opener.name) {this.target=opener.name;}
else {
this.target = opener.name =
'primosWindowName'+Math.floor(Math.random()*10000);
}}">

If the original window exists, then we either set the target attribute
to that window's name. If it has no name, we create a new, random, name
and assign it to both the target attribute and the window's name.

Warning, untested code. I did test that you can set the window's name
dynamically in Opera 7, Mozilla and IE 6.

This will probably fail if the user has navigated the original window
away from your pages and onto a new domain.

/L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,522
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top