Home > Web Front-end > JS Tutorial > JavaScript method to transfer values ​​​​to each other between two forms on the same page_javascript skills

JavaScript method to transfer values ​​​​to each other between two forms on the same page_javascript skills

WBOY
Release: 2016-05-16 15:45:40
Original
1593 people have browsed it

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>
Copy after login

I hope this article will be helpful to everyone’s JavaScript programming design.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template