views:

552

answers:

2

I currently have an Ajax pop up window displayed from the main page of my application. In this pop up I have select list and I want to pass the selected value from the pop up back to the main page when the user closes the pop up window.

I feel there is an elementary way to do this, but I can't seem to figure it out.

+1  A: 

Using window.opener

http://www.webreference.com/js/tutorial1/opener.html

Brendan Heywood
+1  A: 

When you open a popup window via javascript (no matter if the content is via ajax or some other technique) you can easily control it.

For your problem you need window.opener which points back to originating document: the clean one:

in the popup code have:

<body onclose="window.opener.somevar=document.getElementById('myid').value;window.opener.orsomefunction('value');">
<input id="myid"/>
</body>

this way, when you close it it sets a variable and/or calls a function.

you could also set the set-function on a button or directly on the input

<button onclick="window.opener....;window.close();"/>
Niko