Link to home
Start Free TrialLog in
Avatar of princehyderabad
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:OpenWindow()"><img src=".." ></a>
</td>

Thx
PH
Avatar of boonleng
boonleng
Flag of Malaysia image

<html>
<head>
<title>Select Company</title>
<script>
function passData(what){
 var main = window.opener.document ? window.opener.document : window.opener;
 main.getElementById('company').value = what;
 self.close();
}
</head>
<body>
<form><select onChange="passData(this.value);">
<option>Company A
<option>Company B
</select></form>
</body>
</html>
Avatar of princehyderabad
princehyderabad

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 ???
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("COMPANY_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 ????


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(myId);
}

function closeWindow(value) {
  field.value = value;
  win.close();
}
</script>
</head>
<body>
  <form>
    <input type="text" name="company" id="comp0"><a href="javascript:openWindow('comp0')">open</a><br/>
    <input type="text" name="company" id="comp1"><a href="javascript:openWindow('comp1')">open</a><br/>
  </form>
</body>
</html>

child.htm
------------
<html>
<body>
<a href="javascript:window.opener.closeWindow('ABC')">ABC</a>
<a href="javascript:window.opener.closeWindow('XYZ')">XYZ</a>
</body>
</html>
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.opener.closeWindow('ABC')">ABC</a><select id="role"><option>Read Only<option>Admin</select>
..

ASKER CERTIFIED SOLUTION
Avatar of boonleng
boonleng
Flag of Malaysia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial