uncaught typeerror无法读取undefined的属性'value'

时间:2013-07-25 15:44:25

标签: javascript

这个计算器在html上运行正常,当我将它添加到WordPress安装时,它现在抛出了这个错误:

未捕获的typeerror无法读取未定义的属性“值”。

Chrome控制台说它就是这条线。

var TotalAreaAccum = ((document.forms[0].Area1LenFt.value * 1)+(document.forms[0].Area1LenIn.value * 1)/12)*((document.forms[0].Area1WidFt.value * 1)+(document.forms[0].Area1WidIn.value * 1)/12);

这是html中的工作计算,当它被添加到php站点(WP)时它停止工作。 Example Link。任何帮助将不胜感激

 <script language="JavaScript">
  function Round2Dollars(amount) {
// Converts amount to a formatted string with leading dollar sign
// and rounded to 2 decimal places
// Copyright 1998 Millennium Software, Inc by Paul F Johnson www.msi-web.com
//
var dollars = "$"+Math.floor(amount)+".";
var cents = 100*(amount-Math.floor(amount))+0.5;
result = dollars + Math.floor(cents/10) + Math.floor(cents%10);
return result;
    }

    function Round2(amount) {
// Converts amount to a formatted string 
// rounded to 2 decimal places
// Copyright 1998 Millennium Software, Inc by Paul F Johnson www.msi-web.com
// modified from Round2Dollars by drs 2/24/00
var dollars = Math.floor(amount)+".";
var cents = 100*(amount-Math.floor(amount))+0.5;
result = dollars + Math.floor(cents/10) + Math.floor(cents%10);
return result;
 }

    function calcul8() {
// Calculations for form
// Calculate the total square footage of up to five rectangles.
//
var TotalAreaAccum = ((document.forms[0].Area1LenFt.value * 1)+(document.forms[0].Area1LenIn.value * 1)/12)*((document.forms[0].Area1WidFt.value * 1)+(document.forms[0].Area1WidIn.value * 1)/12);
TotalAreaAccum = TotalAreaAccum + ((document.forms[0].Area2LenFt.value * 1)+(document.forms[0].Area2LenIn.value * 1)/12)*((document.forms[0].Area2WidFt.value * 1)+(document.forms[0].Area2WidIn.value * 1)/12);


document.forms[0].TotalSqFt.value = TotalAreaAccum;
document.forms[0].WasteSqFt.value = Round2(TotalAreaAccum * .05);
document.forms[0].TotalMatlReq.value = Round2(TotalAreaAccum * 1.05);
document.forms[0].TotalCost.value = Round2Dollars(document.forms[0].TotalMatlReq.value * document.forms[0].CostPSF.value);

   }

  function resetform() {
// Reset field on form to default values
document.forms[0].Area1LenFt.value = "0";
document.forms[0].Area1LenIn.value = "0";
document.forms[0].Area1WidFt.value = "0";
document.forms[0].Area1WidIn.value = "0";
document.forms[0].Area2LenFt.value = "0";
document.forms[0].Area2LenIn.value = "0";
document.forms[0].Area2WidFt.value = "0";
document.forms[0].Area2WidIn.value = "0";
document.forms[0].CostPSF.value = "0.00";
document.forms[0].TotalSqFt.value = "0";
document.forms[0].WasteSqFt.value = "0";
document.forms[0].TotalMatlReq.value = "0";
document.forms[0].TotalCost.value = "0.00";
   }
   </script>

1 个答案:

答案 0 :(得分:0)

HTML

中没有任何带 CostPSF 名称的元素