尝试在blur上将数据从一个文本框复制到另一个文本框,或单击isn';不工作的javascript

尝试在blur上将数据从一个文本框复制到另一个文本框,或单击isn';不工作的javascript,javascript,html,Javascript,Html,我想知道这个脚本使用单选按钮将文本从一个框复制到另一个框是否正确。因为它不适合我。它们是两种不同的形式,我不知道这是否重要。它们都是文本框,我希望表单总计中的数据复制到表单利润中 <script type="text/javascript"> function data_copy() { if(document.TOTALS.copy[0].checked){ document.profit.SOLDTO1.value=document.TOTALS.SOLDTO.value

我想知道这个脚本使用单选按钮将文本从一个框复制到另一个框是否正确。因为它不适合我。它们是两种不同的形式,我不知道这是否重要。它们都是文本框,我希望表单总计中的数据复制到表单利润中

 <script type="text/javascript">
  function data_copy()
{

if(document.TOTALS.copy[0].checked){
document.profit.SOLDTO1.value=document.TOTALS.SOLDTO.value;
document.profit.['ACCNT#1'].value=document.TOTALS.ACCNT#.value;
document.profit.INVNUM1.value=document.TOTALS.INVNUM.value;
document.profit.SLM1.value=document.TOTALS.SLM.value;
document.profit.totfaccost1.value=document.TOTALS.totfaccost.value;
document.profit.tot_frt_cost1.value=document.TOTALS.tot_frt_cost.value;
document.profit.totlandcost1.value=document.TOTALS.totlandcost.value;
}else{
document.profit.SOLDTO1.value="";
document.profit.['ACCNT#1'].value="";
document.profit.INVNUM1.value="";
document.profit.SLM1.value="";
document.profit.totfaccost1.value="";
document.profit.totlandcost1.value="";

}

}

</script>


 Click to fill out profit analysis<input type="radio" name=copy value='yes' onclick="data_copy()";>

函数数据_copy()
{
如果(document.TOTALS.copy[0]。已选中){
document.price.SOLDTO 1.value=document.TOTALS.SOLDTO.value;
单据.利润。['ACCNT#1'].value=document.TOTALS.ACCNT#value;
单据.利润.INVNUM1.value=document.TOTALS.INVNUM.value;
document.profit.SLM1.value=document.TOTALS.SLM.value;
document.price.totfacost1.value=document.TOTALS.totfacost.value;
document.price.tot_firt_cost1.value=document.TOTALS.tot_firt_cost.value;
document.price.totlandcost1.value=document.TOTALS.totlandcost.value;
}否则{
文件.利润.SOLDTO1.价值=”;
文件。利润。['ACCNT#1'].value=“”;
单据.利润.投资金额1.价值=”;
单据.利润.SLM1.价值=”;
文件.利润.总成本1.价值=”;
文件.利润.总成本1.价值=”;
}
}
单击此处填写利润分析
document.TOTALS.ACCNT.value
中的散列
#
不是有效的变量名字符,因此无法解析。

此:

document.profit.ACCNT#1.value="";
是一个语法错误。尝试:

document.profit['ACCNT#1'].value = "";

您引用的两个位置都需要修复。

通常最好使用
document.getElementById
查找文档中的元素:

document.getElementById("SOLDTO1").value = document.getElementById("SOLDTO").value;
我还将从元素名称和/或ID中删除任何哈希标记或特殊字符