submiting to a parent window from a popup child window?

M

midnight_use_only

hi all,
quick question, how do you submit a form to a parent window from a
child popup window? i have the following and all online documentation
*suggests* that it should work but it does NOT:

// Parent window:
<script language="JavaScript">
function popup(url, name)
{
window.open(url, name, "width=800,height=600,scrollbars=yes");
return false;
}
</script>
....
<form name=form1 method=post action=something.php>
<input type=hidden name=h1 value='' >
<a href="#"
target="childWindowName" onclick="return popup('url.php','Some
name');">Pop</a>
....
</form>

// Now in the child popup window
<script language="JavaScript">
function handleSubmit(aValue)
{
var myParent = opener.document.forms.form1;
myParent.h1.value=aValue;
myParent.submit(); // ERROR: Object doesn't support this property
or method
return true;
}
</script>
<a href=# onclick="handleSubmit(2006);">Submit</a>

i have spent a few hours searching online and all the examples
indicates that this example should work but it doesn't, not in IE or
FF. in FF, nothing happen and in IE, the following error show up:

Object doesn't support this property or method

any idea? thanks!
 
S

Seige

First things first, both your pages (parent and child) must be under
the same domain and/or path. If this is the case then it could be that
you gave the window wrong names...

where does childWindowName reference to? is it necessary for it to be
there?

'Some name' shouldn't have any spaces in between, so you might want to
consider 'Some_name'

otherwise you could try the onsubmit attribute in form1
 
M

midnight_use_only

comments below...
First things first, both your pages (parent and child) must be under
the same domain and/or path. If this is the case then it could be that
you gave the window wrong names...

yes the parent and the child window are under the same domain and same
path.
where does childWindowName reference to? is it necessary for it to be
there?

it's not referenced anywhere. correct me if i am wrong (most likely),
target="childWindowName" is the name of the child window and is
required for a popup right? otherwise, i could have use something like
target=_blank
'Some name' shouldn't have any spaces in between, so you might want to
consider 'Some_name'

actually, it doesn't have space in the actual code. iti's my mistake to
have a space here
otherwise you could try the onsubmit attribute in form1

i suppose i could do that but i am more interested to find out why my
solution doesn't work in the first place where all online documentation
and code example suggests that it should. i think you are on the right
track that i must have some sort of name-reference thing mess up
between the child and the parent window but the thing is i can get a
reference of the parent window and setting hidden field variables and
such, it's just the submit() method keep saying it's not support
 
S

Seige

Hmm... i'm clueless as to why this happen. Usually when something like
this happens, I would regard it as another "Browser-Securit-Issue" and
proceed with the workaround. (aka onsubmit)
 
D

dzhuo1

unfortunetly, onsubmit() won't work too because the form is not
submited so the event is never trigger. i did solve this prolbme by
using this:

// myParent.submit(); -- does NOT work
myParent.mySubmitButton.click(); // this does work

by using the click() event, it does exactly what i need. i still have
no idea why submit() doesn't work.
 

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,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top