2014-06-11 3 views
0

에 작동하지 않는 것은 자바 스크립트 오류가 발생합니다 : catch되지 않은 형식 오류 : 나는 무엇을 말할 수에서 onchange를OnChange 이벤트 코드에 따라 선택 상자

는이 스크립트가 작동합니다 orderquantity : 정의되지 않은 함수가 아닙니다. 나는이 문제를 꽤 많이 봤다. 모든 sugestions에는 충돌을 일으키지 않도록 이름 바꾸기가 포함되어 있지만 충돌하는 요소 이름이나 ID가 없는지 확인했다.

인쇄상의 문제 일 수 있지만 문제를 찾을 수 없습니다. 도와주세요.

<script type="text/javascript"> 

function orderquantity(myvalue) 
    { 
     if (myvalue == "Custom") { 
      document.getElementByID('cquant').style.display="inline-block"; 
     }else{ 
      document.getElementByID('cquant').style.display="none"; 
      document.getElementByID('customquant').value=""; 
     } 
    } 
</script> 

<select name="quantity" id="quant" onchange="orderquantity(this.selectedIndex);"> 
    <option value="MatchLast" selected="selected">Same as Last Time</option> 
    <option value="500">500</option> 
    <option value="1000">1000</option> 
    <option value="2500">2500</option> 
    <option value="5000">5000</option> 
    <option value="10000">10000</option> 
    <option value="Custom">Custom Quantity</option> 
</select> 

<div id="cquant" style="display: none;"> 
    <input type="text" name="CustomAmount" id="customquant"> 
</div> 

답변

1

대신 this.selectedIndex 사용 this.value. 또한 : getElementByID은 코드에서 getElementById이어야합니다. 합의

Example

0

는, 그것은 당신에서 getElementById와 가능성 문제 이상이다. 당신이 찾고있는 것은 getElementById입니다.

Nolutysses가 말했듯이, 당신도 그렇게해야합니다. 가치. 그러나 .innerHTML을 추가하는 것 외에는 가지고있는 것과 함께있을 수도 있습니다. 그래서 this.selectedIndex.innerHTML이 될 것입니다. 하지만이 값은 더 짧고 이해하기 쉽습니다.