Passing information between windows

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Passing information between windows

Post by Luke »

Is it possible to pass a variable from a popup window back to the window that popped it up? For instance: I want to be able to click on something in the popup and have it change the dropdown (select element) in the original window. Is this possible?
angus
Forum Newbie
Posts: 10
Joined: Sat Sep 17, 2005 5:43 pm

Post by angus »

are you using php?

could you put it into a session variable and collect it on the other end.

or if your using JS to do all this set a cookie ...
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

I'm pretty sure is has to be client-side. I don't have direct access to any files because I am working with MIVA merchant. I thought there was a wy to do something sorta like this, but I can't find info about it:
(This is the popup window)

Code: Select all

mainWindowName.formname.formelement.value = "FOO";
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

Code: Select all

opener.document...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

This comes straight out of phpBB's user administration. I am sure there is some importance on form names and window names.

This page pops the window open when you click the 'Find a username' button...

Code: Select all

<form method="post" name="post" action="formaction.php">
Select a User<br />
<input type="text" class="post" name="username" maxlength="50" size="20" /> 
<input type="hidden" name="mode" value="edit" />
<input type="submit" name="submituser" value="Look up user" class="mainoption" /> 
<input type="submit" name="usersubmit" value="Find a username" class="liteoption" onClick="window.open('./../search.php', '_search', 'HEIGHT=250,resizable=yes,WIDTH=400');return false;" />
This code allows you to select a user from a select list and it will send that information back to the calling page...

Code: Select all

<script language="javascript" type="text/javascript">
<!--
function refresh_username(selected_username)
{
	opener.document.forms['post'].username.value = selected_username;
	opener.focus();
	window.close();
}
//-->
</script>

<form method="post" name="search" action="search.php?mode=searchuser">
<select name="username_list">
<option value="me">me</option>
<option value="you">you</option>
</select>&nbsp; 
<input type="submit" class="liteoption" onClick="refresh_username(this.form.username_list.options[this.form.username_list.selectedIndex].value);return false;" name="use" value="Select" />
<br /><br />
<a href="javascript:window.close();" class="genmed">Close Window</a>
</form>
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

Awesome... works PERFECTLY!!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sweet! That's at least two times in my life that I helped someone! :wink:
Post Reply