469,568 Members | 1,620 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,568 developers. It's quick & easy.

targeting main window from popup

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

Oct 28 '05 #1
5 2660
> 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
}

Oct 28 '05 #2
VK
> targeting main window from popup

Unless you're working for intranet you should re-think your model using
virtual div/iframe popup.

Your current approach will not work for about 50% of your current web
visitors and about 80% by the end of this year.

See for details:
<http://groups.google.com/group/comp.lang.javascript?start=60&hl=en>

Oct 28 '05 #3
VK wrote:
targeting main window from popup
Unless you're working for intranet you should re-think your model using
virtual div/iframe popup.

Your current approach will not work for about 50% of your current web
visitors and about 80% by the end of this year.


Where exactly do you got these numbers and dates from?
See for details:
<http://groups.google.com/group/comp.lang.javascript?start=60&hl=en>


Most certainly not from there.
PointedEars
Oct 28 '05 #4
Joshie Surber wrote:
What should I give in ???? for target?
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

Oct 28 '05 #5
Hemanth wrote:
Joshie Surber wrote:
> What should I give in ???? for target?
window.onload = function() {
f = document.getElementById('myform');
var f = document.forms['myform'];

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

if (f)
{ f.target = window.opener; }

*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";
}
[...] should work.


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:

<meta http-equiv="Content-Script-Type" content="text/javascript">
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/...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/>

</FAQENTRY>
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
Oct 28 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by William Starr Moake | last post: by
7 posts views Thread by Jens Peter Hansen | last post: by
1 post views Thread by Piotr | last post: by
reply views Thread by suresh191 | last post: by
4 posts views Thread by guiromero | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.