princehyderabad
asked on
Passing value from popup window
hi experts,
I have a page which displays company name apart form other fields when i wanna change companay name I click change-image beside company name and popup windows opens showing list of company names. I click on any company name, the popup should be closed and that clicked company name should replace the exisiting company name on parent page.
Company name
xyz [change-image]
abc [change-image]
Remember I'm getting parent page company name from DB and placed in table cell.
<td>
rs.getString("COMPANY_NAME ")
<a href="javascript:OpenWindo w()"><img src=".." ></a>
</td>
Thx
PH
I have a page which displays company name apart form other fields when i wanna change companay name I click change-image beside company name and popup windows opens showing list of company names. I click on any company name, the popup should be closed and that clicked company name should replace the exisiting company name on parent page.
Company name
xyz [change-image]
abc [change-image]
Remember I'm getting parent page company name from DB and placed in table cell.
<td>
rs.getString("COMPANY_NAME
<a href="javascript:OpenWindo
</td>
Thx
PH
You can refer to this tutorial http://www.webreference.com/js/tutorial1/opener.html
<html>
<head>
<title>Select Company</title>
<script>
function passData(what){
var main = window.opener.document ? window.opener.document : window.opener;
main.getElementById('compa ny').value = what;
self.close();
}
</head>
<body>
<form><select onChange="passData(this.va lue);">
<option>Company A
<option>Company B
</select></form>
</body>
</html>
<head>
<title>Select Company</title>
<script>
function passData(what){
var main = window.opener.document ? window.opener.document : window.opener;
main.getElementById('compa
self.close();
}
</head>
<body>
<form><select onChange="passData(this.va
<option>Company A
<option>Company B
</select></form>
</body>
</html>
ASKER
the above URL is good example I followed the same. But I'm unable to get value from child window.
Parent Window >> Onclick JS -- Child Window Opens >> I click the any one name in List >> child window get close>> AND NO VALUE IS CHANGED IN PARENT FORM.FIELDNAME.VALUE ??? wHY
I did exactly the same what the URL mentioned ???
Parent Window >> Onclick JS -- Child Window Opens >> I click the any one name in List >> child window get close>> AND NO VALUE IS CHANGED IN PARENT FORM.FIELDNAME.VALUE ??? wHY
I did exactly the same what the URL mentioned ???
ASKER
Well I think I now the problem why its not display, but dont the soloution.
the above URL has single <input field > example and mine is multiple <input filed> with same name.
my Code:
while (rs.next())
{
..
<input type="text" name="cname" size="8" value="<%=rs.getString("CO MPANY_NAME ")%>" />
<a href="javascript:showList( )"><image src="../images/a.bmp" /></a>
..
}
Since I hv multiple line sharing same name "cname" which causing child window confusion ????
the above URL has single <input field > example and mine is multiple <input filed> with same name.
my Code:
while (rs.next())
{
..
<input type="text" name="cname" size="8" value="<%=rs.getString("CO
<a href="javascript:showList(
..
}
Since I hv multiple line sharing same name "cname" which causing child window confusion ????
You need to uniquely identify the fields, you can add a counter to the loop and append the value of the counter to the field id.
parent.htm
-------------
<html>
<head>
<script>
var win;
var field;
function openWindow(myId) {
win = window.open('child.htm', 'win');
field = document.getElementById(my Id);
}
function closeWindow(value) {
field.value = value;
win.close();
}
</script>
</head>
<body>
<form>
<input type="text" name="company" id="comp0"><a href="javascript:openWindo w('comp0') ">open</a> <br/>
<input type="text" name="company" id="comp1"><a href="javascript:openWindo w('comp1') ">open</a> <br/>
</form>
</body>
</html>
child.htm
------------
<html>
<body>
<a href="javascript:window.op ener.close Window('AB C')">ABC</ a>
<a href="javascript:window.op ener.close Window('XY Z')">XYZ</ a>
</body>
</html>
parent.htm
-------------
<html>
<head>
<script>
var win;
var field;
function openWindow(myId) {
win = window.open('child.htm', 'win');
field = document.getElementById(my
}
function closeWindow(value) {
field.value = value;
win.close();
}
</script>
</head>
<body>
<form>
<input type="text" name="company" id="comp0"><a href="javascript:openWindo
<input type="text" name="company" id="comp1"><a href="javascript:openWindo
</form>
</body>
</html>
child.htm
------------
<html>
<body>
<a href="javascript:window.op
<a href="javascript:window.op
</body>
</html>
ASKER
Works good, may I ask one more thing here. In Child if I want to add one more form field to each record then who would I get its value.
Child.htm
eg:
..
<a href="javascript:window.op ener.close Window('AB C')">ABC</ a><select id="role"><option>Read Only<option>Admin</select>
..
Child.htm
eg:
..
<a href="javascript:window.op
..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.