2011-05-12 7 views
0

사람이 오류로 날 halpe 수 :자바 스크립트 잡히지 않는 유형 오류?

Uncaught TypeError: Cannot read 
property 'length' of undefined 

website

당신이 아래의 가격을 변경해야 콤보의 값을 변경할 수 있지만,이

function update_price_select2(o, element_name) 
{ 

    var sel_obj = null; 
    var element = null; 
    //price_original = <?php //echo substr($products_price,0,-1); ?>; 
    //alert("Preço Original:" + price_original); 
    if (document.getElementById) // DOM3 = IE5, NS6 
    { 
     sel_obj = document.getElementById(o); 
     //alert("sel_obj "+ sel_obj); 
     element = document.getElementById(element_name); 
     //alert("element "+ element); 
    } 
    //alert(o); 
    //alert(element_name); 
    var index = sel_obj.selectedIndex; 
    //alert(o+" index"); 
    var price_array = option_price[sel_obj.id]; 
    var price = price_array[index]; 
    var price_for_operation = price.substr(0,price.length -1); //the price from the option choosen 

    if (price_for_operation == '') 
    { 
     price_for_operation = 0; 
    } 

    //Ao preço original, vamos retirar o preço da variável que este tinha anteriormente. 
    current_product_price = current_product_price - option_price[sel_obj.id + '_current']; 
    //Vamos colocar o valor actual da variável seleccionada 
    option_price[sel_obj.id + '_current'] = price_for_operation; 

    if (price_for_operation != 0) 
    { 
     var final_price = roundNumber(parseFloat(current_product_price) + parseFloat(price_for_operation),2); 
     final_price = final_price.toFixed(2); 
    } 
    else 
    { 
     var final_price = current_product_price.toFixed(2); 
    } 
    //Nos save the decimal value, without the € or $, so we can use it in the next options call 
    current_product_price = final_price; 
    final_price = final_price + money_simbol; 

    if (final_price != "") 
    {  
     display_updated_price(final_price, element); 
     update_allowbuy(final_price); 
    } 

} 
+1

는 –

+0

@Sachin Shanbhag 안녕하세요 –

+0

업데이트 몇 가지 예제 코드를 필요 895 행의 "order is null"입니다. 메시지가 정확히 어디에서 발화됩니까? – reporter

답변

0

오류가 발생한 행을 게시 할 수 있습니까? 오류는 발견 할 수없는 객체의 속성 길이에 액세스하려고 시도한다고 알려줍니다. 나는 당신의 페이지를 방문 할 때

가 나는 smiliar 오류 :

var order = document.getElementById('".BUTTON_IN_CART."'); 
order.style.visibility = 'visible';` 

는 "순서"정의되지라고 나에게 이야기를,이 변수 BUTTON_IN_CART을 찾을 수 없기 때문입니다 따라서 그것은을받지 않습니다 요소! 찾고있는 요소가 있는지 항상 확인해야합니다.

편집 :

는 요소가 발견되었는지 확인하기 위해 코드를 확장 : 난 그냥 오류 메시지를 가지고 당신의 웹 사이트를로드 할 때

if (document.getElementById) // DOM3 = IE5, NS6 
{ 
    sel_obj = document.getElementById(o); 
    //alert("sel_obj "+ sel_obj); 
    element = document.getElementById(element_name); 
    //alert("element "+ element); 
} 

if(sel_obj == null) { alert("Sell Obj not found!"); } 
if(element == null) { alert("Element not found!"); } 
+0

감사합니다. 존재하는지 확인합니다. –

2

확인하는 경우 작동하지 않는 경우 귀하의 "price"은 유효한 값입니다. "price"이 정의되지 않은 경우 코드에서와 같이 "price.length"줄을 사용할 수 없습니다. 내 생각 엔 price이 확실하게 undefined 일 것입니다.

+0

가격이 정의되지 않았지만 그 이유는 무엇입니까? –

+0

@ 대니얼 - Price가 정의되지 않은 이유를 확인하기 위해 몇 가지 경고 또는 로그 문을 추가하십시오. Price_Array에있는 항목을 확인하고 색인을 작성하십시오. 문제점을 줄인 다음 해결하십시오. –