Data transfer code between Javascript forms-form effects

Source: Internet
Author: User
One, the simplest is the same page in the form of data transmission.
For example, there are two forms on a Web page, a text box in each form, and a button. The point button pairs each other to manipulate the value of each other's text box. The example we give is to pay a text box to another text box. The specific HTML code is as follows:
Copy Code code as follows:

<title>untitled document</title>
<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 ">
<body>
<form name= "Form1" method= "Post" action= "" >
<input type= "text" name= "TextField" >
<input type= "button" Name= "Submit" value= "1--------->2" onclick= "OK ()" >
</form>
<form name= "Form2" method= "POST" action= "" >
<input type= "text" name= "Textfield2" >
<input type= "button" Name= "Submit" value= "2----->1" onclick= "Ok1 ()" >
</form>
</body>

The above HTML code, you may notice the Onclik code, there are two functions, followed by the JavaScript code:
Copy Code code as follows:

<script language= "JavaScript" >
function ok ()
{
Document.form2.textfield2.value=document.form1.textfield.value;
}
function Ok1 ()
{
Document.form1.textfield.value=document.form2.textfield2.value;
}
</script>

Two, the second is data transfer between the text boxes of a form between two windows. In fact, this can be based on the original to carry out a number of extensions on it. about how to create pop-up windows, forms in the form of the code, here is not much to say, now here to say how to manipulate the parent window of the text box in the form of data. The specific code is as follows:
Copy Code code as follows:

<script language= "JavaScript" >
function ok ()
{
Opener.document.form2.textfield2.value=document.form1.textfield.value
}
</script>

Three, the third is the frame page between the form of the text box between the data transfer.
The place to note is the wording of the frame:
Copy Code code as follows:

<frameset cols= "505,505" >
<frame src= "test.htm" name= "Leftr" id= "Leftr" >//define the name of the frame
<frame src= "test2.htm" id= "right" name= "right" >
</frameset>
<noframes><body>
</body></noframes>

The specific implementation code is as follows:
Copy Code code as follows:

<script language= "JavaScript" >
function ok ()
{
Parent.leftr.document.form2.textfield2.value
=document.form1.textfield.value
}
</script>

The simple method of manipulating text box values between these three types of Windows is achieved, and the other thing to be aware of is their relationship.
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.