Piotr wrote:
I have popup window (window.open) where I put any value in input
field. After submit I wan to to return to the main window and get value from
popup window. How to close popup window and return to the main after
submit?
<html>
<head>
<title>Master Form Page</title>
<script type="text/javascript">
var Fwin = null;
function openFWin(url)
{
var w = 160,
h = 100,
l = 200,
t = 180;
Fwin =
open(url,'Fwin','width='+w+',height='+h+',left='+l +',top='+t+',status=0');
if (Fwin && !Fwin.closed)
Fwin.focus();
return false;
}
</script>
</head>
<body onload="document.mainform.reset()">
<form name="mainform">
<input name="data" type="text" /><a href="#" onclick="return
openFWin('formpop.html')">←set data</a>
</form>
</body>
</html>
[formpop.html]
<html>
<head>
<title>Pop Up Form</title>
<script type="text/javascript">
function transfer_to_opener(oSrcForm, sDestFormName)
{
if (opener && !opener.closed)
{
var f, els;
if ((f = opener.document.forms[sDestFormName]) && (els = f.elements))
els['data'].value = oSrcForm.elements.data.value;
top.close();
return false;
}
}
</script>
</head>
<body bgcolor="#82a4c8" onblur="setTimeout('top.focus()', 100);">
<form name="popForm"
style="width:100%;text-align:center;padding-top:20px;"
onsubmit="return transfer_to_opener(this, 'mainform')">
<input name="data" type="text" value="enter data"
onfocus="this.value=''" />
<br /><br />
<input type="submit" value="done" />
</form>
</body>
</html>
This doesn't submit the new data, just transfers it over to the 'main'
window, a typical request. If you want the data submitted, remove
'top.close();' and 'return false;' from the function, and return an
action page to the pop-up with a bit of JS that closes the window
unconditionally.