submit

lulu50
lulu50 used Ask the Experts™
on
Hi,

I have a parent window and a child window.

How can I have the child window submit the parent window.

so, I have a button on the child window when the user click on it should confirm
if they want to continue to submit the parent form - yes or no.  

if yes then the child window should submit the parent window then close the child window.

if no then just close the child window.

Thanks,
Lulu
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2017
Distinguished Expert 2018
Commented:
If the parent opens the child the then the child can simply do

window.opener.document.formname.submit()

Example
t670.html - the parent window
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
  $('#childwinbtn').click(function() {
   // Open child in a new window
    window.open('t672a.html','_blank');
    return false;
  });
});
</script>
<style type="text/css">
</style>
</head>
<body>
<div>
<p>Dummy form to demonstrate the concept. Posts data to a php script that echo's
the data back</p>
<form name="myformwindow" action="t672.php" method="post">
  Enter a value here <input type="text" name="fieldname" />
  <input id="childwinbtn" type="button" value="Open Child Window" />
</form>
</div>
</body>
</html>

Open in new window

t672a.html - the child window - contains a button that submits the parent
<!doctype html>
<html>
<head>
<title>Test</title>
<script src="http://code.jquery.com/jquery.js"></script>
<script type="text/javascript">
$(function() {
  $('#parentsubmit').click(function() {
    window.opener.document.myformwindow.submit();
    window.close();
    return false;
  });
});
</script>
<style type="text/css">
</style>
</head>
<body>
<div>
<form>
  <input id="parentsubmit" type="button" value="Submit parent" />
</form>
</div>
</body>
</html>

Open in new window

t672.php - simple php script to dump the results of the submit
<pre>
<?php
if ($_POST) print_r($_POST);
else echo "Nothing submitted";
?>
</pre>

Open in new window


If the child is not the same domain as the parent you might want to look at postmessage
You can look here for more info
http://javascript.info/tutorial/cross-window-messaging-with-postmessage

Author

Commented:
julianH,


both forms are on the same domain.

I am not getting error but it's not submitting the form

I get this message: "form not submitted"

//this is on the child form

$('#SubmitForm').click(function() {
 	window.opener.document.LogEntryFrm.submit();
    window.close();
    return false;
  });

 <input type="button" id="SubmitForm" name="SubmitForm" value="Submit" />

Open in new window



what is this part?
where would I put it?

<pre>
<?php
if ($_POST) print_r($_POST);
else echo "Nothing submitted";
?>
</pre>

Open in new window

Author

Commented:
I am using coldfusion can I use the php code above?
Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
I am using coldfusion can I use the php code above?
The PHP is not part of the solution - it is just there to demonstrate that the form was actually posted. You need to point the form submit to whatever form processing script you are using.

Author

Commented:
the LogEntryFrm is on the parent window
so, I have it like this
      window.opener.document.LogEntryFrm.submit();
but, I still can't get it to submit the parent form.

Author

Commented:
Thank you
Most Valuable Expert 2017
Distinguished Expert 2018

Commented:
You are welcome - thanks for the points.

Did you manage to get it to work?

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial