javascript null값 처리 질문좀요..!

javascript null값 처리 질문좀요..!

QA

javascript null값 처리 질문좀요..!

답변 2

본문

선택옵션에서 옵션을 선택후에 장바구니로 값을 넘기는 부분을 하고있는데요.

관리자 모드에서 상품에 선택옵션을 주면 괜찮은데, 선택옵션을 안주면

Uncaught TypeError: Cannot read property 'options' of null(…) 

이렇게 오류가 나옵니다. 

 

 

*스크립트 부분 입니다.


function fitem_submit(f)

{

var select = document.getElementById("it_option_1");

var select_val = select.options[select.selectedIndex].value;

var text = select.options[select.selectedIndex].text;

 

    if (document.pressed == "장바구니") {

        f.sw_direct.value = 0;

if(select_val.length == 0){

alert("옵션을 선택해주세요.");

return false;

}else{

f.text;

alert(text);

}

    } else { // 바로구매

        f.sw_direct.value = 1;

f.text;

    }

 

옵션값이 null값이라 생기는 오류같은데 선택옵션이 없는 상품을 처리하려면 어떻게 처리해야할까요..?

이 질문에 댓글 쓰기 :

답변 2

자체 해결했습니다.

 

function fitem_submit(f)

{

var select = document.getElementById("it_option_1");

if(select != null){

var sellength = select.length;

var select_val = select.options[select.selectedIndex].value;

var text = select.options[select.selectedIndex].text;

 

    if (document.pressed == "장바구니") {

        f.sw_direct.value = 0;

if(select_val.length == 0){

alert("옵션을 선택해주세요.");

return false;

}else{

f.text;

alert(text);

}

 

    } else { // 바로구매

        f.sw_direct.value = 1;

f.text;

}

 

}else{

 

    if (document.pressed == "장바구니") {

        f.sw_direct.value = 0;

 

    } else { // 바로구매

        f.sw_direct.value = 1;

 

    }

}

답변을 작성하시기 전에 로그인 해주세요.
QA 내용 검색
질문등록
전체 0
© SIRSOFT
현재 페이지 제일 처음으로