Code for passing values between two Javascript forms

Source: Internet
Author: User

For example, our new window fatherpage.htm:
XML-Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function OpenChildWindow ()
{
Zookeeper open('childpage.htm ');
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "OpenChild" onclick = "OpenChildWindow ()"/>

Then, you can use window. opener in childpage.htm to access elements in the parent form:
XML-Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function SetValue ()
{
Extends extends opener.doc ument. getElementById ('txtinput'). value
= Document. getElementById ('txtinput'). value;
Window. close ();
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "SetFather" onclick = "SetValue ()"/>

The secret can be changed:
XML-Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Function OpenChildWindow ()
{
Var child = zookeeper open('childpage.htm ');
Child.doc ument. getElementById ('txtinput'). value
= Document. getElementById ('txtinput'). value;
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "OpenChild" onclick = "OpenChildWindow ()"/>

By judging whether the subform reference is null, we can also control that it can only open one subform:
XML-Code:
Copy codeThe Code is as follows:
<Script type = "text/javascript">
Var child
Function OpenChildWindow ()
{
If (! Child)
Child = zookeeper open('childpage.htm ');
Child.doc ument. getElementById ('txtinput'). value
= Document. getElementById ('txtinput'). value;
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "OpenChild" onclick = "OpenChildWindow ()"/>

This is not enough. When the child form is closed, the child variable of the parent form must be cleared; otherwise, the child form cannot be re-opened after it is closed:
XML-Code:
Copy codeThe Code is as follows:
<Body onunload = "Unload ()">
<Script type = "text/javascript">
Function SetValue ()
{
Extends extends opener.doc ument. getElementById ('txtinput'). value
= Document. getElementById ('txtinput'). value;
Window. close ();
}
Function Unload ()
{
Window. opener. child = null;
}
</Script>
<Input type = "text" id = "txtInput"/>
<Input type = "button" value = "SetFather" onclick = "SetValue ()"/>
</Body>

Related Article

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.