2013-08-17 47 views
1

我用兩個文本框來概括號,但顯示錯誤..未捕獲的ReferenceError:txtMaking_F沒有定義

<script> 
     function getPrice(tMaking, tHandeling, tTotal) { 
      var obj_tMaking = document.getElementById(txtMaking_F) 
      var obj_tHandeling = document.getElementById(txtHandeling_F) 
      var obj_tTotal = document.getElementById(txtTotal_F) 
      if (obj_tMaking.value != "" && obj_tHandeling.value != "") { 
       obj_tTotal.value = parseInt(obj_tMaking.value) + parseInt(obj_tHandeling.value); 
      } 
      else { 
       obj_tTotal.value = ""; 
      } 
     } 
    </script> 
</head> 
<body> 
    <input name="grdView$ctl08$txtMaking_F" type="text" id="grdView_ctl08_txtMaking_F" class="classMaking" onchange="javascript:return getPrice('grdView_ctl08_txtMaking_F','grdView_ctl08_txtHandeling_F','grdView_ctl08_txtTotal_F');" style="width: 60px;" /> 
    <input name="grdView$ctl08$txtHandeling_F" type="text" id="grdView_ctl08_txtHandeling_F" class="classHandling" onchange="javascript:return getPrice('grdView_ctl08_txtMaking_F','grdView_ctl08_txtHandeling_F','grdView_ctl08_txtTotal_F');" style="width: 60px;" /> 
    <input name="grdView$ctl08$txtTotal_F" type="text" id="grdView_ctl08_txtTotal_F" class="classTotal" style="width: 100px;" /> 
</body> 

enter image description here

+1

你的問題是什麼?你不明白這個錯誤嗎?這意味着變量'txtMaking_F'沒有被定義。 –

+0

謝謝我犯了一個愚蠢的錯誤 – Nisar

回答

2

我認爲你有錯別字的功能

function getPrice(tMaking, tHandeling, tTotal) { 
      var obj_tMaking = document.getElementById(tMaking) 
      var obj_tHandeling = document.getElementById(tHandeling) 
      var obj_tTotal = document.getElementById(tTotal) 
            //     ^- removed extra "txt" & "_F" 

      if (obj_tMaking.value != "" && obj_tHandeling.value != "") { 
      obj_tTotal.value = parseInt(obj_tMaking.value) + parseInt(obj_tHandeling.value); 
     } 
     else { 
      obj_tTotal.value = ""; 
     } 
    } 

我假設傳遞給該函數的值是id的,在這種情況下應該有tMakingvar obj_tMaking = document.getElementById(txtMaking_F)而不是txtMaking_Fobj_tHandelingobj_tTotal相同。

+0

謝謝塞爾吉奧。你幫我 我犯了一個愚蠢的錯誤... – Nisar

+0

@NISAR,它不傻,我們都犯錯誤。它很高興有更多的人在看代碼:) – Sergio

相關問題