View Full Version : submitting to parent window
joe_mama
10-30-2003, 12:14 PM
Hi, I posted a similar question but didn't get the answers I was looking for, so I'm restating my question. I have one window that opens another popup window through the click of a button. I use the window.open() method to do this. In this new popup window, the user can enter text in a textarea and submit its form. I want this form to be submitted to the parent window(the parent will save it in a db.) and then displayed in the parent window. I don't want the popup to reference a textfield in the parent, I actually want the popups form to be submitted to the parent so that I can pick up its form parameters. I believe this form submittion can be done with javascript, but I really am not sure. Can anyone help me?
Thank you
piglet
10-30-2003, 02:49 PM
Yes - I can! You could continue the original thread if you's wanted...
You just need the form to use method "get", and the action to the page which can receive the data:
<html>
<body>
<form method="GET" action="http://www.webxpertz.net/faqs/jsfaq/passvars/showgetvars.html">
<input type="text" name="foo" value="something"><br>
<input type="radio" name="bar" value="yes">
<input type="radio" name="bar" value="no">
<input type="checkbox" name="mybox">
<input type="submit" value="Submit">
</form>
</body>
</html>
There is a faq describing this target page and method on this link (http://www.webxpertz.net/faqs/jsfaq/passvars.php#formurl)
joe_mama
10-30-2003, 03:39 PM
No, I would like the parent window(browser) to be the one receiving the parameters, not the child window. The popup/child window is the just for entering in info. Its submission to should be to the parent window(browser) that opended it, not the page that opened it.
Thanks
piglet
10-30-2003, 04:24 PM
Hi,
Then you're out of luck.
The parent and child windows can communicate whatever information you want through the window object (created by window.open when the popup was made) or through the "opener" object of the child window.
The child window can submit to an html page as detailed before - but it can't submit to a specific client process!
n8thegreat
10-30-2003, 04:34 PM
you could just have the popup process it, then use javascript to refresh the main window to another page
unless there some reason why it HAS to submit to the main window
joe_mama
10-30-2003, 04:34 PM
Ok, can u suggest a way around this then. I was thinking that when the child window's form gets submitted, it submits to itself and store the info/parameters in the database. Then all I have to do is refresh the parent window/browser and because it retrieves the info from the database eash time it gets called, the info will then be displayed there. The only problem is how refresh the parent window from the child. I believe that I had tried this a while ago but scrapped the idea because if I forced the refresh through javascript i would get a prompt asking if I really wanted to refresh the browser. Can you tell me a way around that, as well as how to refresh the parent window from the child.
Thanks for you help
joe_mama
10-30-2003, 04:36 PM
Oh i didnt see this previous reply. Thats exactly what i was thinking. Except how do you fresh the parent and how do you do it without getting a prompt.
Thanks
piglet
10-30-2003, 04:36 PM
to refresh the parent window:
opener.location.reload(true);
scoutt
10-30-2003, 04:42 PM
joe_mama: why did you start 3 threads on this?
http://www.htmlforums.com/showthread.php?s=&threadid=30444
http://www.htmlforums.com/showthread.php?s=&threadid=30447
and this one.
if you didn't get a clear answer then please post in the same thread. and would you look at that, almost the same answer I suggested when you first asked this question 2 days ago. and what prompt? if the parent didn't submit the form then there should be no prompt.
and welcome piglet, glad to have you here. :)
joe_mama
10-30-2003, 04:46 PM
Sorry, yes i should have continued the same thread and no your answer was not the similar.
scoutt
10-30-2003, 04:47 PM
really?
onclick="opener.location.submit='page.php'; return false;"
opener.location.reload(true);
looks pretty close to me, except I was submitting a form
joe_mama
10-30-2003, 04:51 PM
Wow, it uses the same object, but two very different method, and yours didn't solve my problem to begin with. Thats why I wrote another thread.
scoutt
10-30-2003, 04:57 PM
all you had to say was it didn't work and somebody else would come along. no need to start another thread.
and I said it might not work as I don't do javascript.
joe_mama
10-30-2003, 05:01 PM
Yaa, I know that now. I screwed up. I apologize to everyone for now conforming to the forum etiquette, but thank you for replying anyways.
Jon Hanlon
10-30-2003, 08:50 PM
The popup window can reference the window that opened it through the opener object.
The popup needs to populate a form on the opener, and then submit this form (on the opener).
self.opener.forms.myForm.field1.value = "whatever";
self.opener.forms.myform.field2.value = "you like";
self.opener.forms.myForm.field3.value = self.forms.popupForm.somefield.value; // say from a textarea
self.opener.forms.myForm.submit() // submits form in opener
setTimeout("self.close()",1000) // close popup in 1 second
piglet
10-31-2003, 03:40 AM
Hi Jon,
I tried him with that method on this thread (http://www.htmlforums.com/showthread.php?s=&threadid=30447) - we've now shown him all the different ways there are available to him.....if he wants another way he'll have to write a new browser to work the way he wants!
vBulletin® v3.6.7, Copyright ©2000-2009, Jelsoft Enterprises Ltd.