2014-01-05 4 views
-4

다음과 같은 jquery 함수는 형태 정수 값을 입력하고 실시간으로 업데이트합니다. 그것은 하나의 값이 null onload 일 때 작동하지 않고 오류를주는 것을 제외하고는 잘 동작합니다. 내가 얻을null 값을 가진 양식 필드 추가하기

function updateTotal(formObj) { 
      var total = 0; 
      total += parseInt(formObj.amt1.value, 10) 
      total += parseInt(formObj.amt2.value, 10) 
      total += parseInt(formObj.amt3.value, 10) 
      total += parseInt(formObj.amt4.value, 10) 
      total += parseInt(formObj.amt5.value, 10) 
      total += parseInt(formObj.amt6.value, 10) 
      total += parseInt(formObj.amt7.value, 10) 
      total += parseInt(formObj.amt8.value, 10) 
      formObj.sum.value = total 
     } 

오류가

TypeError: document.getElementById(...) is null 
document.getElementById('amt6').focus(); 

날 내가 하나가 null 값을 무시하거나 일부 체크 표시를 할 수있는 방법을 알려 주시기 바랍니다 있습니다. 감사합니다

+0

언뜻보기에 오류가있는 것처럼 보입니다. 그러나 나는 빠른 대답을 게시 할 것이다. –

답변

0
var test = parseInt(formObj.amt1.value, 10); 

if(test !== null){ 
    total += test; 
} 

정보를 제공하는 방법이 많이 있습니다.

관련 문제