sibylle_kennedy
asked on
javascript invoke submit on parent window from child window
I have a parent window that contains multiple submit buttons, depending on what option the user chooses (i.e. change address; process order; save as quote. If certain conditions are met, I need to pop up a new child window with some further instructions. After reading the instructions, the user has to choose to either "change address" or "process order", or just close the popup. Based on which button the user chooses in the child window, I need to automatically submit the corresponding button on the parent window.
Here's what I've got so far:
PARENT WINDOW:
=============
<script language="JavaScript">
myWindow = window.open("inc_verify_ad dress.cfm" , "addrWindow", 'toolbar=no,width=460,heig ht=300,res izable=yes ,scrollbar s=yes');
myWindow.focus();
</script>
<form name="checkout" action="act_parent.cfm" method="POST">
<input type="submit" name="change_address_a" value="change" onselect="submit();"><br>
<input type="submit" name="process_order_a" value="order" onselect="submit();">
</form>
CHILD WINDOW:
============
<script language="JavaScript">
function chg_addr()
{
window.opener.document.che ckout.chan ge_address _a.selecte d;
}
function prc_order()
{
window.opener.document.che ckout.proc ess_order_ a.selected ;
}
</script>
<input type="button" name="change_address" value="change" onclick="chg_addr();window .close();" >
<input type="button" name="process_order" value="process" onclick="prc_order();windo w.close(); ">
The child window is closed, but the form is not submitted on the parent window.
Alternately, I have successfully set a value for an input field in the parent window, from the child window, with this syntax:
CHILD WINDOW:
window.opener.document.che ckout.chan ge_address _a.value = "true";
However, the onchange event does not seem to be working; the form is not submitted.
PARENT WINDOW:
function submit_this()
{
document.checkout.submit_b tn.submit( );
}
<form name="checkout" action="act_parent.cfm" method="POST">
<input type="text" name="change_address_a" value="" onchange="submit_this();">
<input type="submit" name="submit_btn" value="submit">
</form>
I would appreciate comments on any approach that has worked for you in the past. Thanks!!!
Here's what I've got so far:
PARENT WINDOW:
=============
<script language="JavaScript">
myWindow = window.open("inc_verify_ad
myWindow.focus();
</script>
<form name="checkout" action="act_parent.cfm" method="POST">
<input type="submit" name="change_address_a" value="change" onselect="submit();"><br>
<input type="submit" name="process_order_a" value="order" onselect="submit();">
</form>
CHILD WINDOW:
============
<script language="JavaScript">
function chg_addr()
{
window.opener.document.che
}
function prc_order()
{
window.opener.document.che
}
</script>
<input type="button" name="change_address" value="change" onclick="chg_addr();window
<input type="button" name="process_order" value="process" onclick="prc_order();windo
The child window is closed, but the form is not submitted on the parent window.
Alternately, I have successfully set a value for an input field in the parent window, from the child window, with this syntax:
CHILD WINDOW:
window.opener.document.che
However, the onchange event does not seem to be working; the form is not submitted.
PARENT WINDOW:
function submit_this()
{
document.checkout.submit_b
}
<form name="checkout" action="act_parent.cfm" method="POST">
<input type="text" name="change_address_a" value="" onchange="submit_this();">
<input type="submit" name="submit_btn" value="submit">
</form>
I would appreciate comments on any approach that has worked for you in the past. Thanks!!!
window.opener.document.che ckout.subm it();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<html>
<head>
<script language="JavaScript"><!--
var windowReference;
function openPopup() {
windowReference = window.open('popup.htm','w indowName' );
if (!windowReference.opener)
windowReference.opener = self;
}
//--></script>
</head>
<body>
<form name="formName" onSubmit="alert('submit triggered')">
</form>
</body>
</html>
And then in popup.htm:
<form>
<input type="button" value="Submit" onClick="opener.document.f ormName.su bmit()">
</form>
<head>
<script language="JavaScript"><!--
var windowReference;
function openPopup() {
windowReference = window.open('popup.htm','w
if (!windowReference.opener)
windowReference.opener = self;
}
//--></script>
</head>
<body>
<form name="formName" onSubmit="alert('submit triggered')">
</form>
</body>
</html>
And then in popup.htm:
<form>
<input type="button" value="Submit" onClick="opener.document.f
</form>