在两个不同的表单中复制textarea中的值(两个表单都在不同的.asp文件中) [英] Copy value in textarea within two different forms (both forms in different .asp file)

查看:102
本文介绍了在两个不同的表单中复制textarea中的值(两个表单都在不同的.asp文件中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两种不同的形式,分别是formA和formB,其中每个form在不同的.asp文件中。在每种形式中都有一个textarea,用户需要在其中输入他们的地址。除了文本区域在formB有一个复选框,用户可以点击它,如果两个textareas的地址是相同的。我的问题是如何使用复选框将值从formA中的textarea复制到formB中的textarea。我不能想出来,因为它涉及到不同的形式从两个不同的.asp文件。希望你能帮助。谢谢。

I have two different forms which is formA and formB where each form in different .asp file. In each form there is a textarea where the user need to enter their address. Beside the textarea in formB there is a checkbox where the user can click on it if the address for both textareas are the same. My question is how can I copy the value from textarea in formA into the textarea in formB by using checkbox. I can't figure it out because it involve to different forms from two different .asp file. Hope you can help. Thank you.

推荐答案

如果这是一个类似结帐程序,您要将送货地址的值复制为相同

If this is something like a checkout procedure where you want to copy the value of shipping address to be the same as mailing address, it's quite simple to do.

在表单B中,您基本上将另一个地址(从表单A或从存储中加载)加载到隐藏的地址表单字段,然后检测复选框在javacsript中更改。

In form B, you basically load the other address (from form A or from storage if you persist it) in a hidden form field and then detect the checkbox is changed in javacsript. If it is ticked, then copy the hidden form value to the new textbox.

您需要的3个文件(全部在b asp页面中):

3 pieces that you need (all in form b asp page):

<%
  Dim addressInFormA

  'Retrieve the address from previous page (form a)
  'Change to Request.Form or Request.QueryString for more efficient code
  'Using Request as a catch all here.
  'Need to add necessary clean up code to prevent script injection vulnerability here
  'For simplicity sake, I'm not doing it here.
  addressInFormA = Request("txtAddress")
%>

<input type="hidden" name="hidAddress" id="hidAddress" value="<%=addressInFormA%>" />

<input type="checkbox" name="chkUseAddressA" id="chkUseAddressA" onclick="checkCopyAddress()" />
<input type="text" name="txtAddress" id="txtAddress" />

<script>
function checkCopyAddress() {
  'Get me the checkbox
  'This is just for example, in reality I won't do it this way.
  var checkBox = document.getElementById("chckUseAddressA");

  document.getElementById("txtAddress").value = 
(checkBox.checked) ? document.getElementById("hidAddress").value : "";
}
</script>

这篇关于在两个不同的表单中复制textarea中的值(两个表单都在不同的.asp文件中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆