How to Get Values from popup to parent

Posted by druva | HTML, JS, utils | Wednesday 9 December 2009 7:19 am

The requirement is
I had a button wen i click it a popup window will display with some values.
I have to select those values. the selected values must display in the parent window.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>

 <body>

 <form>

 <table border=1>
 <th>Name</th>
 <th>Country</th>
 <tr>
 <td><input id="name" name="name" /></td>
 <td><input id="country" name="country" /></td>
 </tr>
 </table>

 <input type="button" name="choice" onClick="window.open('popup.html','popuppage',' width=350,toolbar=1,resizable=1,scrollbars=yes, height=300,top=100,left=100');" value="Add">

 </form>

 </body>

</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head>

 <SCRIPT LANGUAGE="JavaScript">
 <!-- Begin
 function sendValue (n, c){
 var name = n.value;
 var country = c.value;
 window.opener.document.getElementById('name').value = name;
 window.opener.document.getElementById('country').value = country;
 window.close();
 }
 //  End -->
 </script>

 </head>
 <body>

 <form name="selectform">

 <table width="250">

 <tr>
 <td>
 Enter your name:
 </td>
 <td>
 <input type="text" name="name" id="name">
 </td>
 </tr>

 <tr>
 <td>
 Select your country:
 </td>
 <td>
 <select name="country">
 <option value="India">India</option>
 <option value="United States">United States</option>
 <option value="United Kingdom">United Kingdom</option>
 <option value="Germany">Germany</option>
 <option value="France">France</option>
 </select>
 </td>
 </tr>

 <tr>
 <td>
 <input type=button value="submit" onClick="sendValue(this.form.name, this.form.country);">
 </td>
 </tr>

 </table>

 </form>

 </body>
</html>