Javascript:这个脚本有什么问题?

Alx*_*xan -1 javascript asp-classic

我在我的一个页面上成功使用了这个计算脚本,但是当我在另一个页面中重用它时.该页继续说"未捕获的TypeError:无法读取未定义的属性'值'"我不明白这个脚本有什么问题.那么请你帮帮我吧.谢谢.

<script>
function startCalc(){ //automatically calculate total after discount when adding new order
  interval = setInterval("calc()",1);
}
function calc(){
 // for calculate each product order
 var price;
 var qty;
 var od_total;
  price = document.myform.od_price.value;
  qty = document.myform.od_qty.value; 
  od_total = (price * 1) * (qty * 1);
  document.myform.od_total.value = od_total.toFixed(2);  
}

function stopCalc(){
  clearInterval(interval);
}
</script>
Run Code Online (Sandbox Code Playgroud)

我用过这个脚本

<input id="od_qty" name="od_qty" type="text" size="8" value="" maxlength="100" onFocus="startCalc();" onBlur="stopCalc();">
<input id="od_price" type="text" size="4" value="<%=rs.fields.item("cust_price")%>" onFocus="startCalc();" onBlur="stopCalc();"  >
<input id="od_total"  name="od_total" type="text" size="10" value="" maxlength="100" readonly="true">
Run Code Online (Sandbox Code Playgroud)

Tim*_*the 6

这是页面结构的问题.该字段必须是在一个名为形式myform进行document.myform.od_price.value工作.您可以将行更改为

document.getElementById('od_price').value
Run Code Online (Sandbox Code Playgroud)

只使用id而不是表单名称选择它.第二个领域也是如此 - od_qty.