Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing a form field value on another window

Status
Not open for further replies.

pedroemarques

Technical User
Joined
Apr 12, 2006
Messages
2
Location
PT
Hello! My first post:)

I have a page that lauches a popup windows:
Code:
<a href="javascript:;" onclick="window.open('popup.php','','width=190,height=380');">

On that popup I ask the user to choose from a list of options and i change a form field value in the first window:
Code:
<script type="text/javascript">
<<!--
function selecionar(value) {
  window.opener.document.form.field.value=value;

what I want to do is to close this popup, open another one automatically and repeat the process a second time. I tried something like this after the code above:
Code:
  window.open('popup2.php','','width=190,height=380');
  self.close();}
//-->
</script>

it seems to work, but one the second popup i lost the opener reference to the first window and it does't write the second form field value:


Code:
<script type="text/javascript">
<!--
function selecionar(value) {
  window.opener.opener.document.formfield.value=value;
  self.close();}
//-->
</script>

I really need the second popup automatically, and not from the main window, because the second page is a php mysql statement that makes a select based on the first popup result.

Please help me....
 
You could try setting the opener property from the first popup:

Code:
var secondWin = window.open('popup2.php', '', 'width=190,height=380');
secondWin.opener = self.opener;

I've not tried it, but give it a whirl!

Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
that, or you could have the first popup call the [tt]window.open[/tt] function of the first window by modifying your script something like this:
Code:
  window.[COLOR=red]opener.[/color]open('popup2.php','','width=190,height=380');
  self.close();}
//-->
</script>
In the case you mentioned above, [tt]window.opener.opener[/tt] wouldn't work for you becuse the first popup has already closed, which sets [tt]window.opener[/tt] to [tt]null[/tt], so you can't access it's properties anymore.



I hope this helps;
Rob Hercules
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top