two windows, sending data between....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

two windows, sending data between....

Post by 9902468 »

Sorry if I missed something, but after a little searching and googleing I was unable to find the answer:

I have one page that has few add [something] buttons. When user presses the button it opens new window, where user can select something from a list and when he/she presses ok the newer window should close, and changes should be updated to the main window.

The story so far: I happily made script to open new window, and controls to that new window.

Problem:
How can I tell the main window to update it self after user has pressed ok (the new window ok button, values are in session, so only refresh is required..) Also how can I now close the new window?

Thanks,

-9902468
Beefy
Forum Newbie
Posts: 6
Joined: Wed Aug 14, 2002 5:06 am

Post by Beefy »

You could reload the main window with http-meta-refresh periodically, but that won't really solve your problem.
Another solution: The new window sends the information to the old window and closes itself...

Code: Select all

/* mainwindow.php */
if($go='ok') echo 'case 1';
else echo 'case 2 <input type="submit">"; /* This button opens the newwindow */

/* newwindow.php
<form action="mainwindow.php">
<input type="submit" name="go" value="ok"> <!-- This button sends all information to the main window (look at the form action) -->
</form>
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Post by 9902468 »

I thought that

Code: Select all

<form action=somepage.php>
just loads somepage.php file to THIS window? (where the form tag is)
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Post by 9902468 »

ok. I can close the window with js (onsubmit) , so is it even possible to tell that other window to refresh? Anyone?
Beefy
Forum Newbie
Posts: 6
Joined: Wed Aug 14, 2002 5:06 am

Post by Beefy »

9902468 wrote:I thought that

Code: Select all

<form action=somepage.php>
just loads somepage.php file to THIS window? (where the form tag is)
You're right.
I thought that would'nt matter. :D

Well, I'm sorry, but I don't know any JS.
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

Post by fatalcure »

yes there is a way, look up javascript and passing variables from one browser to the next, im pretty sure it can be done, its even done (something similar) on this forum, when you click on VIEW MORE EMOTICONS, where you select an emoticon from a remote window, and it adds it to the main window's Message Body. So you could just call a function in the main window from the Remote window and the function would refresh the page.

Hope this helps.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

Try this:

In the parent page add:

Code: Select all

<input type="hidden" name="var_name">
In the child page add:

Code: Select all

<script>
    function SubmitToParentPage(form)
    &#123;
        window.opener.document.forms&#1111;0].var_name.value=
        form.child_page_var.value;
     
        form.submit();
        window.close();
    &#125;
</script>
add this to the bottom of the child page:

Code: Select all

<input type="button" value="Submit" 
  onClick="SubmitToParentPage(this.form)">
Direwolf
fatalcure
Forum Contributor
Posts: 141
Joined: Thu Jul 04, 2002 12:57 pm
Contact:

boooooya...

Post by fatalcure »

try this:

PARENT WINDOW CODE

Code: Select all

<script language="JavaScript">
<!-- 
function new_window() &#123;
	self.name = "Parent_Window"; 
	var new_window = "scrollbars,resizable,width=250,height=150,left=700,top=25";
	OpenWindow = window.open("remote.htm", "remote", new_window);
&#125;

function refresh_window() &#123;
	window.location.reload( true );
&#125;

-->
</script>

<a href="javascript:onClick=new_window();">Open Remote Window</a>
REMOTE WINDOW CODE

Code: Select all

<a href="javascript:refresh_window();" target="Parent_Window" onClick="window.close()">Refresh main window and Close this remote.</a>
:)
User avatar
9902468
Forum Commoner
Posts: 89
Joined: Thu Jun 06, 2002 6:39 am
Location: Europe

Post by 9902468 »

Ok thanks! I'll try out what you succested.
Post Reply