child window assignment to the parent window implementation ideas and case demonstration _ Practical skills

Source: Internet
Author: User
Today insus.net practice JavaScript, implement a child window from the parent window, and after the child window handles some results, assign the result to the parent window's text box. Can see the effect:

Create two ASPX pages in the site, one is pagea.aspx and the other is pageb.aspx:
In the pagea.aspx
Copy Code code as follows:

<script type= "Text/javascript" >
function popUp (URL) {
Objsubwin = window.open (URL, "Popup", "toolbar=no,scrollbars=no,location=no,statusbar=no,menubar=no,resizable=0," Width=300,height=80 ");
Objsubwin.focus ();
}
Function SetValue (val) {
var amount = document.getElementById (' <% = Textboxamount.clientid%> ');
Amount.value = val;
}
</script>

Then in the <body> node, pull a TextBox and a button:
Copy Code code as follows:

Amount:
<asp:textbox id= "Textboxamount" runat= "Server" enabled= "false" ></asp:TextBox>
<asp:button id= "Button1" runat= "Server" text= "Call child window" onclientclick= "popUp (' pageb.aspx ')"/>

OK, the parent page completes, next writes the pageb.aspx child page, or writes the JavaScript script first, also has two functions, one is verifies the text box only to enter the number, another is calculates the method, in the Calc () method, has the method which calls to the parent window.
Copy Code code as follows:

<script type= "Text/javascript" >
function IsNumeric (keycode) {
Return ((keycode >= && keycode <=) | | keycode = 8)
}
Function Calc () {
if (Window.opener!= null &&!window.opener.closed) {
var qty = document.getElementById (' <% = Textboxqty.clientid%> ');
var price = document.getElementById (' <% = Textboxprice.clientid%> ');
Window.opener.SetValue (parseint (qty.value) * parseint (Price.value));
}
}
</script>

In the pageb.aspx <body> node, pull two text boxes, one button ammonium button.
Copy Code code as follows:

Quantity <asp:textbox id= "Textboxqty" runat= "Server" onkeydown= "return IsNumeric (Event.keycode);" onpaste= "return false;" Width= "></asp:TextBox>"
* Unit Price <asp:textbox id= "Textboxprice" runat= "Server" onkeydown= "return IsNumeric (Event.keycode);" Onpaste= "return false; " Width= "></asp:TextBox>"
<asp:button id= "Button1" runat= "Server" text= "Calculate" onclientclick= "calc ()"/>

Additionally, for text box validation articles: http://www.jb51.net/article/33586.htm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.