묻고답하기

구조는 1단계 셀렉트값 선택시 2단계옵션리스트가 올라오고
2단계 선택시 3단계옵션리스트가 올라오고
3단계 선택시 3단계옵션리스트가 올라오는 방식입니다.

질문:
1단계 셀렉트값 누를경우 2단계가 나오는데 3단계를 초기화 할수 있는 방법이 없나요?
맨 처음누를때는 순차적으로 잘 작동되는데
4단계까지선택하고 다시 1단계를 누르면 3단계, 4단계 셀렉트값은 이전값 그대로 가지고 있습니다.

즉 1단계 누를때 3, 4단계값 초기화
2단계 누를때 4단계값 초기화 할수 있는 방법을 묻는겁니다.
이 소스는 FirstListItem 이라는 단어를 구글에서 찿아 보면 많이 나오는 소스 입니다.
물론 이소스의 DB 연동은 되어 있지 않고 , 제 개인소스는 되어 있죠.
좋은 하루 되세요.

<script lanuage=javascript>
var FirstList = new Array(2);;
var SecondList = new Array(4);;
var ThirdList = new Array(12);;
var ForthList = new Array(26);;
var nvalue;
var description;


function FirstListItem(nvalue, description) {
    this.nvalue = nvalue;
    this.description = description;
}

function SecondListItem(category,nvalue,description) {
    this.category = category;
    this.nvalue = nvalue;
    this.description = description;
}


function ThirdListItem(category,nvalue,description) {
    this.category = category;
    this.nvalue = nvalue;
    this.description = description;
}


function ThirdListItem(category,category1,nvalue,description) {
    this.category = category;
    this.category1 = category1;
    this.nvalue = nvalue;
    this.description = description;
}

function ForthListItem(category,category1,category2,nvalue,description) {
    this.category = category;
    this.category1 = category1;
    this.category2 = category2;
    this.nvalue = nvalue;
    this.description = description;
}

function prepareData(){

    FirstList[0] = new FirstListItem(0,"매입");
    FirstList[1] = new FirstListItem(1,"매출");
    
    SecondList[0] = new SecondListItem(0,0,"일반매입");
    SecondList[1] = new SecondListItem(0,1,"고정자산매입");
    SecondList[2] = new SecondListItem(1,0,"신고기간분");
    SecondList[3] = new SecondListItem(1,1,"예정누락분");
    SecondList[4] = new SecondListItem(1,2,"예정누락분2");

    ThirdList[0]  = new ThirdListItem(0,0,0,"공제세액");
    ThirdList[1]  = new ThirdListItem(0,0,1,"불공제세액");
    ThirdList[2]  = new ThirdListItem(0,0,2,"계산서");
    ThirdList[3]  = new ThirdListItem(0,0,3,"누락분공제");
    ThirdList[3]  = new ThirdListItem(0,0,4,"누락분공제");
    ThirdList[4]  = new ThirdListItem(0,1,0,"공제세액");
    ThirdList[5]  = new ThirdListItem(0,1,1,"불공정세액");
    ThirdList[6]  = new ThirdListItem(0,1,2,"계산서");
    ThirdList[7]  = new ThirdListItem(0,1,3,"누락분공제");
    ThirdList[8]  = new ThirdListItem(1,0,0,"세금계산서");
    ThirdList[9]  = new ThirdListItem(1,0,1,"기타분");
    ThirdList[10] = new ThirdListItem(1,1,0,"세금계산서");
    ThirdList[11] = new ThirdListItem(1,1,1,"기타분");
    ThirdList[12] = new ThirdListItem(1,1,2,"기타분2");

    ForthList[0]  = new ForthListItem(0,0,0,0,"세금계산서");
    ForthList[1]  = new ForthListItem(0,0,1,0,"비영업용소형승용차");
    ForthList[2]  = new ForthListItem(0,0,1,1,"접대관련매입세액");
    ForthList[3]  = new ForthListItem(0,0,1,2,"필요적기재사항누락");
    ForthList[4]  = new ForthListItem(0,0,1,3,"영수증");
    ForthList[5]  = new ForthListItem(0,0,2,0,"해당없음");
    ForthList[6]  = new ForthListItem(0,0,3,0,"세금계산서");
    ForthList[7]  = new ForthListItem(0,1,0,0,"세금계산서");
    ForthList[8]  = new ForthListItem(0,1,1,0,"비영업용소형승용차");
    ForthList[9]  = new ForthListItem(0,1,1,1,"접대관련매입세액");
    ForthList[10] = new ForthListItem(0,1,1,2,"필요적기재사항누락");
    ForthList[11] = new ForthListItem(0,1,1,3,"영수증");
    ForthList[12] = new ForthListItem(0,1,2,0,"해당없음");
    ForthList[13] = new ForthListItem(0,1,3,0,"세금계산서");
    ForthList[14] = new ForthListItem(1,0,0,0,"세금계산서");
    ForthList[15] = new ForthListItem(1,0,0,1,"고정자산매각");
    ForthList[16] = new ForthListItem(1,0,1,0,"영수증");
    ForthList[17] = new ForthListItem(1,0,1,1,"금전등록기");
    ForthList[18] = new ForthListItem(1,0,1,2,"카드판매");
    ForthList[19] = new ForthListItem(1,0,1,3,"고정자산매각");
    ForthList[20] = new ForthListItem(1,1,0,0,"세금계산서");
    ForthList[21] = new ForthListItem(1,1,0,1,"고정자산매각");
    ForthList[22] = new ForthListItem(1,1,1,0,"영수증");
    ForthList[23] = new ForthListItem(1,1,1,1,"금전등록기");
    ForthList[24] = new ForthListItem(1,1,1,2,"카드판매");
    ForthList[25] = new ForthListItem(1,1,1,3,"고정자산매각");
}


function reFillList(){
    var selValue;
    var nOption;
    selValue = admin.slipcls.value;
    admin.gubun1.length = 0;
//  admin.gubun2.length = 0;
//  admin.gubun3.length = 0;
    for(var i=0; i<SecondList.length;i++){
        if(SecondList[i].category == selValue) {
            nOption = admin.gubun1.length;
            if( selValue == ""){
                nvalue = "";
            }else{
                admin.gubun1.options[nOption] = new Option(SecondList[i].description,SecondList[i].nvalue);
            }
        }
    }
    //alert("testing gubun1 : " + admin.gubun1.options[0].value);

//options[0].selected=true 이면 첫번째거 무조건 선택
//c2는 앞에서 받아온 값
/*
    if(c2 != ""){//수정할때 필요한 값, 2번째 값을 뿌려준다.
        admin.gubun1.options[c2].selected=true;
    }else{
        admin.gubun1.options[0].selected=true;
    }
*/

}

function reFillList1() {
    var selValue;
    var nOption;
    var selValue1;
    var nOption1;
    selValue = admin.slipcls.value;
    selValue1 = admin.gubun1.value;
//  admin.gubun1.length = 0;
    admin.gubun2.length = 0;
//  admin.gubun3.length = 0;

  for(var i=0; i<ThirdList.length;i++){
    if( ThirdList[i].category1 == selValue1 && ThirdList[i].category==selValue) {
        nOption1 = admin.gubun2.length;
            if( selValue == ""){
                nvalue = "";
            }else{
              admin.gubun2.options[nOption1] = new Option(ThirdList[i].description,ThirdList[i].nvalue);  
            }
    }
  }
/*
    if(c2 != ""){ //수정할때 필요한 값, 3번째 값을 뿌려준다.
        admin.gubun2.options[c2].selected=true;
    }else{
        admin.gubun2.options[0].selected=true;
    }
*/
}

function reFillList2(){
    var selValue;
    var selValue1;
    var selValue2;
    var nOption;
    var nOption1;
    var nOption2;
    selValue = admin.slipcls.value;
    selValue1 = admin.gubun1.value;
    selValue2 = admin.gubun2.value;
//  admin.gubun1.length = 0;
//  admin.gubun2.length = 0;
    admin.gubun3.length = 0;
    for(var i=0; i<ForthList.length;i++){
        if(ForthList[i].category2 == selValue2 && ForthList[i].category1==selValue1 && ForthList[i].category==selValue) {
            nOption2 = admin.gubun3.length;
            if( selValue == ""){
                nvalue = "";
            }else{
              admin.gubun3.options[nOption2] = new Option(ForthList[i].description,ForthList[i].nvalue);  
            }
        }
    }
//  admin.gubun3.options[0].selected=true;
}



//---------------------------------------------------------------------------
    var trNormal = "";

function revcheck(theform)
{
    
    for( var i=0; i< document.admin.elements.length; i++) {
        var ele = document.admin.elements[i];
        if(ele.name == 'check')
            ele.checked = !ele.checked;
    }
    return;
}

function allcheck(theform)
{
    for( var i=0; i< document.admin.elements.length; i++) {
        var ele = document.admin.elements[i];
        if ( -1 != ele.name.search(/check/) )
            ele.checked = true;
    }
    return;
}

function discheck(theform)
{
    for( var i=0; i<document.admin.elements.length; i++) {
        var ele = document.admin.elements[i];
        found = ele.name.match(/check*/);
        if( found != null )
            ele.checked = false;
    }
    return;
}

</script>


<body>
<form name="admin">
<tr>
    <td>
1
    <script language=javascript>
    var page="";
    var i;
    prepareData();
    page += "<select name='slipcls'  size='10'  onChange='reFillList();'>";
    for ( i=0; i<FirstList.length;i++) {
        page +="<option value='" + FirstList[i].nvalue + "'";
        if (i==0) {
            page += " selected";
        }
        page += ">"+FirstList[i].description;
    }
    page+="</select>";
    document.write(page);
    </script>  

2
    <select name='gubun1' size="10"  onChange='reFillList1()'>
    <option value="" selected>---------------------</option>
    <SCRIPT LANGUAGE=javascript>
    reFillList();
    </script>
    </select>  

3
    <select name='gubun2' size="10"  onChange='reFillList2()'>
    <option value="" selected>---------------------</option>
    <SCRIPT LANGUAGE=javascript>
    reFillList1();
    </script>
    </select>  

4
    <select name='gubun3' size="10" >
    <SCRIPT LANGUAGE=javascript>
    reFillList2();
    </script>
    </select></td></tr>
</form>    
</body>
</html>
글쓴이 제목 최종 글
XE 공지 글 쓰기,삭제 운영방식 변경 공지 [16] 2019.03.05 by 남기남
김재민 랜덤이미지를 웹상에 올리면 안뜨는 이유 [1] 2007.08.10
김연수 창 아래부분에 링크 주소가 뜨지 않게 하고 싶은데요.  
kasiyas 현재창에서 이루어지지 않습니다.  
김용호 둘로 나위는 사이트 제작 방법 이 궁금합니다.  
김민수 세션관련 질문입니다^^; [1] 2007.08.10
이진수 경고창에 관해.. [1] 2007.08.10
김성미 원 프레임의 메인에 게시판 적용하고 싶어요  
태기김 카테고리 4단 onchange 셀렉트 초기화문제  
최병관 도메인 주소 다른 페이지로 가고 고정으로 되게 하는 방법좀 가르쳐주세욤 [3] 2007.08.10
이재형 윈도우 xp에 iis+ php5 와 mysql설치후 에러 발생..했는데요.  
스틸 IIS설치하고 서버 접속자수나 트래픽을 알 수 있나요?  
구라12단 이미지 링크 두개 이상 거는 방법 있나요?  
치우 인터넷방송 서버 자동으로 교체 되는 프로그램 좀...ㅡㅡ'''' [2] 2007.08.10
안수현 이런형태를 만들려면 어덯게 해야 할가요 [2] 2007.08.10
머구리 이미지를 못 불러오네요. ㅡㅡ;;(서버 문제인가?)  
장영제 팬사이트같은데 보면....  
심종민 테이블 안의 글씨 색깔.. [3] 2007.08.10
라리 별도의 로그인 페이지 관련하여... [1] 2007.08.10
장미선 제로보드에 write.php를 변형하고 있는데요~  
디디다 쇼핑몰 사이트가 있는데요 [1] 2007.08.10
이태엽 하나의 서버에 두가지 방식의 홈페이지 서비스가 가능한지요?  
Tyekanik 링크 하나로 프레임 두개를 동시에 연결 가능한가요? [1] 2007.08.10
이승재 레드햇 7.3인데 동영상 스트리밍을 어떻게 하면 좋을까요?  
이재명 다음처럼 이미지의 모서리 라운딩 만드는 소스에 대해서  
디디다 DB...이용해서 php파일을 만들면 웹에 어떻게 올리나요?; [4] 2007.08.10
Anzara ½™ 제로카운터의 counter_ip 테이블에 관련된 질문입니다.  
박선미 게시판에서 플래쉬 파일 올릴려면..  
현짱 파폭이용시 테이블 밖으로 글자가 튀어나갑니다; [1] 2007.08.10
권율성 제로보드 연동 상태창  
김지웅 부탁드립니다.. [1] 2007.08.10