Home >Web Front-end >JS Tutorial >JavaScript method to transfer values to each other between two forms on the same page_javascript skills
The example in this article describes how to use JavaScript to transfer values between two forms on the same page. Share it with everyone for your reference. The details are as follows:
Sometimes we need to pass the values of the two forms to each other when submitting the form, so how to achieve this? It's actually very simple, just use JavaScript to get the value of any form, and then assign it to another one. You can see the code for details. The code is very interesting and practical.
The screenshot of the running effect is as follows:
The specific code is as follows:
<html> <head> <title>JavaScript同一页面两个表单互相传值</title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> </head> <script language="JavaScript"> function ok() { document.form2.textfield2.value=document.form1.textfield.value; } function ok1() { document.form1.textfield.value=document.form2.textfield2.value; } </script> <body> <form name="form1" method="post" action=""> <input type="text" name="textfield"> <input type="button" name="Submit" value="A表单->传值给B表单" onClick="ok()"> </form> <form name="form2" method="post" action=""> <input type="text" name="textfield2"> <input type="button" name="Submit" value="B表单->传值给A表单" onClick="ok1()"> </form> </body> </html>
I hope this article will be helpful to everyone’s JavaScript programming design.