Java example program to pass value from child window to parent window
We can pass values from a child window in Html to the parent window. This can be done very easily. Here is the program that takes the value from the child window and then pass it to the parent window. To explain this example we have made two HTML files as follows:
Here is the code for both of the HTML files as follows:
| <html> <head> <title> Parent Window </title> </head> <body> <form method=post name="form"> <table border=0 cellpadding=0 cellspacing=0 width=550> <tr> <td> <font size=2>Show Text</font> <input type="text" name='parent_name' size='8'> <a href="javascript:void(0);" name="newWindow" title="Child Window" onClick="window.open('child.html','newWindow','width=550, height=170,left=150,top=200,toolbar=no,resizable=false')"> Open child window </a> </td> </tr> </table> </form> </body> </html> |
| <html> <head> <script langauge="javascript"> function post_value(){ opener.document.form.parent_name.value = document.frm.child_name.value; self.close(); } </script> <title>Child Window</title> </head> <body> <form name="frm" method=post action=''> <table border=0 cellpadding=0 cellspacing=0 width=250> <tr> <td align="center"> Input Text : <input type="text" name="child_name" size=12> <input type="button" value="Submit" onclick="post_value();"> </td> </tr> </table> </form> |
When we will run the parent file it will look like this:

By clicking on the link "Open Child window" link will open child window as

Here we have to insert or input text which is to be passed to the parent window.

Click on the submit button.

Here is the full code of both files. You can download it.
Download Code
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: Pass value from child to parent window View All Comments
Post your Comment