targeting main window from popup

H

Hemanth

Hello there,

I'm running a script that opens a popup window (which is basically a
form with checkboxes and a submit button). When I click the submit
button I want to run a PHP script and target the result to main page (I
mean, update the parent page).

My popup form looks like this:

<form name="form1" action="run.php" method="get" target="???">
<form fields....>
<input type="submit"....>
</form>

What should I give in ???? for target?

Any help is appreciated.

TIA
Hemanth
 
J

Joshie Surber

What should I give in ???? for target?

window.onload = function() {
f = document.getElementById('myform');
f.target = window.opener;
}

should work. If not, since I am assuming that the form just updates
values somewhere that will affect how the main window is displayed, you
may just use the popup as its own target, and after it is submitted
output:
window.onload = function() {
window.opener.reload();
window.close(); // optional
}
 
T

Thomas 'PointedEars' Lahn

H

Hemanth

Joshie said:
window.onload = function() {
f = document.getElementById('myform');
f.target = window.opener;
}

......Thanks for your reply. How should I call this function in the
form??
should work. If not, since I am assuming that the form just updates
values somewhere that will affect how the main window is displayed, you
may just use the popup as its own target, and after it is submitted
output:
window.onload = function() {
window.opener.reload();
window.close(); // optional
}

......I tried something like this before. This what I did:

function update_parent()
{
window.opener.reload();
window.close();
}

<form name="myform" action="run.php" method="get"
onSubmit="javascript:update_parent()">

This runs the PHP script but displays the results in popup page (not in
opener and didn't close the popup window as expected). I'm using
Mozilla and IE browsers. I close the popup window manually and have to
"refresh" the main window to see the results in main window.


function update_parent2(url)
{
window.opener.location.href=url;
window.close();
}
<form name="myform" action="run.php" method="get"
onSubmit="javascript:update_parent2('run.php')">

The javascript works fine but doesn't actually run the PHP script as
expected. I mean, the "update_parent2" replaces the main window with
specified url and closes the popup window but the user (checkbox) input
in popup form is not being used.

Any more pointers would be helpful.

TIA
Hemanth
 
T

Thomas 'PointedEars' Lahn

var f = document.forms['myform'];

is both sufficient and downwards compatible. One probably want to add

if (f)
{}

*if* that approach would work (which it does not).
.....Thanks for your reply. How should I call this function in the
form??

You don't, since it does not work this way. The `target' attribute value
is of type string, not an object reference that window.opener returns.
What may work is

if (f && window.opener && !window.opener.closed)
{
window.opener.name = "foo";
f.target = "foo";
}

No, it definitely should not and will not.
function update_parent()
{
window.opener.reload();
window.close();
}

window.opener.location.reload(), which is probably what you were
looking for, only reloads the opener document. It does not transmit
information newly input by the user.
<form name="myform" action="run.php" method="get"
onSubmit="javascript:update_parent()">

Proprietary `javascript:' URIs do not belong into attribute values for
intrinsic event handlers (as recent discussions have shown, they seldom
belong anywhere). So `javascript:' is but a label here, used only by
the MS script engine. Remove the labels and, for user agents who support
it, properly declare the default scripting language via a `meta' child
element of the `head' element:

This runs the PHP script but displays the results in popup page (not in
opener

BAD. B0rken as designed.
and didn't close the popup window as expected).

Because there is no such intrinsic method as window.opener.reload() in any
AOM (Application Object Model) I know. You received a script runtime error
when trying to call it, but you either overlooked or ignored that.
function update_parent2(url)
{
window.opener.location.href=url;
window.close();
}
<form name="myform" action="run.php" method="get"
onSubmit="javascript:update_parent2('run.php')">

That will not transmit any new data either. You probably notice that
pure fantasy syntax such as this seldom returns a viable result. Get
yourself some decent documentations on HTML, JS, AOM/DOM (there are
plenty on the Net, for free) and develop according to them. See
<http://jibbering.com/faq/>.

<FAQENTRY>

- In section 3.2, the FAQ still refers to

http://devedge.netscape.com/library/manuals/2000/javascript/1.3/reference/

which is dead since almost a year:
<http://www.mozillazine.org/talkback.html?article=5381>

It should point to a mirror like

<http://devedge-temp.mozilla.org/library/manuals/2000/javascript/1.3/reference/>

- Not mentioned in the FAQ, there was also a documentation on JavaScript 1.5
available on DevEdge, which is now hosted at the Mozilla Foundation
website:

<http://developer.mozilla.org/en/docs/JavaScript>

- General information on JavaScript, the ECMAScript 3 Final Specification
and previous editions can be found at

<http://www.mozilla.org/js/>

and

<http://www.mozilla.org/js/language/>

- W3C DOM Level 1 HTML has been obsoleted by W3C DOM Level 2 HTML (see:
"Status of this document" section), yet the FAQ refers to the former's
ECMAScript Language Binding section. It should refer to

<http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>

instead.

- The FAQ does not contain any reference to any W3C DOM Level 3
specification:

<http://www.w3.org/DOM/>

The javascript works fine but doesn't actually run the PHP script as
expected. I mean, the "update_parent2" replaces the main window with
specified url and closes the popup window but the user (checkbox) input
in popup form is not being used.

As I wrote, it's just BAD.
Any more pointers would be helpful.

[x] done


HTH

PointedEars
 

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,769
Messages
2,569,582
Members
45,066
Latest member
VytoKetoReviews

Latest Threads

Top