k Rajesh
06-12-2003, 03:17 PM
before putting this simple question I looked into existing questions, but unfortunately I couldn't find the most related.
I have jsp A having txt box and search button associated to it after click it opens child window with list of peoples and id (UID-First and Last name)
What I need is, once you select any uid, child window should be closed and value of UID (only) should be passed back to parent window (I have txtbox in parent window for it)
thanks in advance
Experiment with the following
In the opener
<P><form name="f1">
<P><input type="text" name="t1" value="Receiving Textbox" size="30" <a href="#null" onclick="popit=open('opened1.htm','pop','top=280,left=390,width=300,height=200');popit.focus()">Open Popup</a>
<P><div id="oDIV">Text From Popup</div>
</form>
--------------------------------------------------------------------------------
In the Popup
<script language="javascript">
<!--
function transfer(str){
if (opener && !opener.closed){
opener.document.f1.t1.value=str;
}
}
</script>
<form name="f1">
<a href="javascript:transfer('This is from the popup link 1')"> Link 1</a>
<P> <button onclick="opener.oDIV.innerHTML='<font color=red> Sample Text From Popup</font>'">Enter Div Text</button>
<P> <input type="text" name="t1" value="Type Some Text In Here"> <input type="button" value="Send" onclick="transfer(document.f1.t1.value)"> <BR>
<P> <button onclick="window.close()"> Done</button>
</form>
beetle
06-12-2003, 03:45 PM
To access a popup window's opener document, just use
window.opener
And from there, you can access he full DOM for the parent window. So, if you have a form "myForm" with an element "myElement"
window.opener.document.myForm.myElement.value = someValue;
k Rajesh
06-12-2003, 04:08 PM
Thank you for quick response
here is my code.
main page
<FORM name="MainPage" method="POST" onsubmit= "return validateData()" action="/Servlets/results">
<TABLE>
<TR>
<TD>Username </TD><TD><input type="text" name="txtUserid" size="20" tabindex="1"></TD>
<TD> <A href="javascript:getIDs('http://Servlets/editorslist.jsp')"><IMG src="/Servlets/searchable.gif" border="0" ALT="Get Editor User Id"> </A></TD>
</TR>
function getIDs(PopUpUrl)
{
var ScreenWidth=window.screen.width;
var ScreenHeight=window.screen.height;
var movefromedge=0;
placementx=(ScreenWidth/2)-((400)/2);
placementy=(ScreenHeight/2)-((300+50)/2);
WinPop=window.open(PopUpUrl,"","width=400,height=300,toolbar=0,location=0,directories=0,status=0,scrollbars=0,menubar=0,resizable=0, left="+placementx+",top="+placementy+",screenX="+placementx+",screenY="+placementy+",");
}
in search window (.jsp)
<html>
<body>
<form name="editorlist" onclick="javascript:transfer(editorlist.editorid.value)" >
<select name="editorid" size=15 >
<%= getOptions()%>
</select>
</form>
</body>
</html>
function transfer(str)
{
opener,document.MainPage.txtUserid.value=str;
window.close();
}
thanks in advance.