By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,028 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

Sending form info from popup window to original window

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
pe**************@yahoo.com (Person) writes:
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
<script type="text/javascript">
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
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.