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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trigger a JS function in window.opener 1

Status
Not open for further replies.

PushCode

Programmer
Dec 17, 2003
573
US
Can I trigger a javascript function on the opener page from the user clicking a button on a popup page?

For example, on the opener (parent) page there will be a js function called: function doselect(fieldvar)

When the user clicks the botton on the popup window, I need to activate that doselect function on the parent window, with "paidAmt" as the fieldvar.

Any idea how I would do that?

Here's my current code for the popup page which works for passing the text field value back to the opener page. What can I add to this to trigger the doselect(fieldvar) function with "paidAmt" as the fieldvar?
Code:
<html><head>
<script language="JavaScript">
	function dosubmit(paidAmount) {                
		   window.opener.document.forms[0].paidAmt.value = document.forms[0].paidAmount.value;
		   window.close();
		}
</script>
</head>
<body>
<form name="frmPaidAmt" method="post">
	Enter Paid Amount: <input type="text" name="paidAmount">
	<br>
	<input type="submit" value=" Make Selection " onclick="dosubmit(paidAmount)">
</form>
</body></html>
 
In the popup, change:

Code:
<input type="[b]submit[/b]" value=" Make Selection " onclick="dosubmit(paidAmount)">

...to:

Code:
<input type="[b]button[/b]" value=" Make Selection " onclick="dosubmit([b]document.frmPaidAmt.[/b]paidAmount)">

And, assuming here that the opener function (doselect()) takes the paid amount as a parameter, in dosubmit(...):

Code:
window.opener.doselect(paidAmount.value);
window.opener = self;
window.close();

You have the right idea. Yes, you can set values and call functions in the opener just by using window.opener.

Let me know if you have any questions about what I did there.

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top