Pass value from child popup window to parent page window using JavaScript--reference
2014-04-08 08:56
483 查看
Here Mudassar Ahmed Khan has explained how to pass value from child popup window to parent page window using JavaScript.
The child popup window must be opened using JavaScript window.open function. And in such case we can access the parent page controls using JavaScript window.opener instance.
In this article I will explain how to pass value from child popup window to parent page window using JavaScript.
The child popup window must be opened using JavaScript window.open function. And in such case we can access the parent page controls using JavaScript window.opener instance.
Parent Page
Inside the Parent Page I have placed a TextBox which is read-only and a button to open the child popup window using the SelectNameJavaScript function.
Popup Child Window Page
The Popup Child Window Page has a DropDownList to choose the name of the person and a button which when clicked calls the SetNameJavaScript function.
This function uses the reference of window.opener property and finds the Parent Page txtName TextBox using document.getElementById method of JavaScript and sets the value selected through the DropDownList to it.
In similar way you can access other controls too of the Parent Page from the Child Popup Window Page
Demo
refernce:
http://www.aspsnippets.com/Articles/Pass-value-from-child-popup-window-to-parent-page-window-using-JavaScript.aspx
The child popup window must be opened using JavaScript window.open function. And in such case we can access the parent page controls using JavaScript window.opener instance.
In this article I will explain how to pass value from child popup window to parent page window using JavaScript.
The child popup window must be opened using JavaScript window.open function. And in such case we can access the parent page controls using JavaScript window.opener instance.
Parent Page
Inside the Parent Page I have placed a TextBox which is read-only and a button to open the child popup window using the SelectNameJavaScript function.
<table border="0" cellpadding="0" cellspacing="0"> <tr> <td> Name: </td> <td> <input type="text" id="txtName" readonly="readonly" /> </td> <td> <input type="button" value="Select Name" onclick="SelectName()" /> </td> </tr> </table> <script type="text/javascript"> var popup; function SelectName() { popup = window.open("Popup.htm", "Popup", "width=300,height=100"); popup.focus(); } </script>
Popup Child Window Page
The Popup Child Window Page has a DropDownList to choose the name of the person and a button which when clicked calls the SetNameJavaScript function.
This function uses the reference of window.opener property and finds the Parent Page txtName TextBox using document.getElementById method of JavaScript and sets the value selected through the DropDownList to it.
<select name="ddlNames" id="ddlNames"> <option value="Mudassar Khan">Mudassar Khan</option> <option value="John Hammond">John Hammond</option> <option value="Mike Stanley">Mike Stanley</option> </select> <br /> <br /> <input type="button" value="Select" onclick="SetName();" /> <script type="text/javascript"> function SetName() { if (window.opener != null && !window.opener.closed) { var txtName = window.opener.document.getElementById("txtName"); txtName.value = document.getElementById("ddlNames").value; } window.close(); } </script>
In similar way you can access other controls too of the Parent Page from the Child Popup Window Page
Demo
refernce:
http://www.aspsnippets.com/Articles/Pass-value-from-child-popup-window-to-parent-page-window-using-JavaScript.aspx
相关文章推荐
- How to pass value from Child window to Parent Window
- 子页面关闭时传值给父页面(pass value from child window to parent window, when the child window is closing)
- Passing Values from Child Page to Parent Page
- How to pass ViewState value from web form page to web user control page?
- How to pass a value from User Control to the Page
- Using ASP.NET and jQuery to Pass Multiple Values from a GridView to Another Page
- Refresh parent window from child window without having to press the refresh button
- 转SSIS 2012 pass values from child package to parent with project deployment model
- 条款20:宁以pass-by-reference-to-const替换pass-by-value
- 【20】宁以pass-by-reference-to-const替换pass-by-value
- how to reference the parent form from the WPF control(Control in ElementHost)
- Effective C++条款20:宁以pass-by-reference-to-const替换pass-by-value
- Refresh parent page window, after closing child window
- jump from a html page to another and then come back to certain part of parent html
- linux异常系列:Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable.
- [Project] Simulate HTTP Post Request to obtain data from Web Page by using Python Scrapy Framework
- Can't connect to X11 window server using ':0.0' as the value of the DISPLAY variable解决方法
- 条款20:宁以pass-by-reference-to-const替换pass-by-value(Prefer pass-by-reference-to-const to pass-by-value)
- 条款20:宁以pass-by-reference-to-const替换pass-by-value
- 条款20:宁以pass-by-reference-to-const替换pass-by-value