将表单隐藏字段变量从一个函数传递到另一个函数

Pass a form hidden field variable from one function to another

本文关键字:函数 一个 另一个 隐藏 表单 字段 变量      更新时间:2023-09-26

second_scored函数由end_date上的onblur事件调用。当用户完成end_date的输入时,除了其他 innerHTML 元素(我省略了这些元素)之外,还会使用来自查询的数据修改隐藏表单元素的值。

如果用户想要接受接受或同意显示的数据(现在在隐藏表单元素中),则可以由用户单独调用 other_scored 函数。他们选中复选框,数据应从second_scored()函数复制到函数other_scored()

问题是当我单击复选框以从隐藏的表单元素复制时,不会复制任何内容,也不会显示。

function second_scored()
{
// { ... }
    document.getElementById('inspection_number').value = '65888';
    document.getElementById('inspection_date').value = '12/31/2007'; 
    document.getElementById('inspection_score').value = '90';
// { ... }
}
function other_scored()
{
  // { ... }
  if (document.getElementById('inspection_number'))
            {
                document.getElementById('b_inspection_number').value = document.getElementById('inspection_number').value;
            }
}

这是形式

FROM: <input name="begin_date" type="text" date" size="12" value="#" id="begin_date">
TO: <input name="end_date" type="text" date" size="12" value="#" id="end_date" onblur="second_score();">
<!-->
I agree to this score: <input type="checkbox" name="IagreePI" id="IagreePI" onclick="other_scored();">
<!-->

你的问题标题说

将表单隐藏字段变量从一个函数传递到另一个函数

因此,如果您想在两个函数中使用变量,则可以使用全局变量,例如,

var variable;
function second_scored()
{
    variable=65888;
}
function other_scored()
{
    console.log(variable);
}

从一个函数设置变量,并从另一个函数访问它。

但是,如果您真的想设置隐藏字段的值并从另一个函数访问它们,请查看此 Jsbin 示例。(我放了一个 saperate 按钮来执行other_scored()函数,因为你还没有为此提供你的 html)