http://myhome.gimhae.go.kr/cugain/cugain_pds/cugain_board_javadata/javascript/composite_selectbox/composite_selectbox.htmlhttp://myhome.gimhae.go.kr/cugain/cugain_pds/cugain_board_javadata/javascript/composite_selectbox/composite_selectbox.zip
링크1 : 소스 다운로드
링크2 : 예제 보기

--------------------------------------------------------------------------------------
                 |    JS+XML 연동                           |   Iframe+DB연동
--------------------------------------------------------------------------------------
로딩회수    |           1                                      |   주(대분류)셀렉트메뉴 를 선택할때마다 iframe을 리프래쉬
연동데이터 |         XML                                   |   DB,파일DB
파싱여부    |    클라이언트에서 로딩후 바로 출력  |   파일DB일 경우 필요..
--------------------------------------------------------------------------------------

//////////////////////////////////////////////////////////////////////////////
themecate.xml 파일
//////////////////////////////////////////////////////////////////////////////
<?xml version="1.0" encoding="euc-kr"?>
<root>
<index  code="A" text="게임">
        <itemA code="AA" text="온라인 게임" />
        <itemA code="AB" text="비디오 게임" />
        <itemA code="AC" text="PC 게임" />
        <itemA code="AD" text="게임 매거진"/>
        <itemA code="AE" text="일반 게임" />
</index>
<index code="B" text="만화/애니">
        <itemB code="BA" text="일본만화/애니" />
        <itemB code="BB" text="한국만화/애니" />
        <itemB code="BC" text="순정" />
        <itemB code="BD" text="무협" />
        <itemB code="BE" text="코믹" />
        <itemB code="BF" text="작가" />
        <itemB code="BG" text="창작" />
        <itemB code="BH" text="만화일반" />
</index>
</root>
//////////////////////////////////////////////////////////////////////////////
0070.HTM 파일
//////////////////////////////////////////////////////////////////////////////
<SCRIPT LANGUAGE="JavaScript">
var xmlDoc;
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
//셀렉트 DB 로드
xmlDoc.load("../themecate.xml");

function themeCate_Load(){
        //대분류 인덱스 값 정리하기
        cnt=xmlDoc.getElementsByTagName("index").length;
        this.text=new Array(cnt);
        this.code=new Array(cnt);
        for(i=0;i<cnt;i++){
                this.code[i]=xmlDoc.getElementsByTagName("index/@code").item(i).text;
                this.text[i]=xmlDoc.getElementsByTagName("index/@text").item(i).text;
        }
}

//대분류 카테리스트 출력
function themeCate_List() {
        //대분류 리스트 객체 반환
        themeSel=new themeCate_Load();
        cnt=themeSel.code.length;
        for(i=0;i<cnt;i++) {
                selCnt=opt.options.length;opt.options.length++;
                opt.options[selCnt].text=themeSel.text[i];
                opt.options[selCnt].value=themeSel.code[i];
        }
}

//소분류 셀렉트 출력
function themeCate_Change(t) {
        //이전 소분류셀렉 초기화
        opt2.options.length=1;
        //선택된 대분류의 코드값을 가진 소분류 리스트를 가져온다.
        sel=t.selectedIndex;
        code=t.options[sel].value;
        tree=xmlDoc.getElementsByTagName("item"+code+"/@text");
        cnt=tree.length-1;
        for(i=0;i<=cnt;i++){
                selCnt=opt2.options.length++;
                opt2.options[selCnt].text=tree.item(i).text;
        }
}
</SCRIPT>

<!--대분류셀렉트-->
<select name="opt" onchange="themeCate_Change(this)">
        <option>--대분류--</option>
</select>

<!--소분류셀렉트-->
<select name="opt2">
        <option>--소분류--</option>
</select>

<!--대분류셀렉트 목록 출력-->
<script>themeCate_List()</script>
---------------------------------------------------------------------------------------------------
XML 트리구조
작성방법은 HTML과 비슷하나 태그를 임의로 생성 가능합니다.
단  </iframe></html>처럼 끝나는지 않는 <br>  같은 단독태그들은
<br /> 처럼 태그뒤에 공백과 / 를 포함해야합니다. 그리고 태그안에
어트리뷰트(속성) 값들은 반드시 "으로시작해서 "으로 끝나야합니다

<index code="A" text="언어/글자">
        <itemA text="가나다라마바사" />
        <itemA text="ABCDEF" />
</index>
<index code="B" text="게시판">
        <itemB text="제로보드" />
        <itemB text="미니보드" />
</index>


번호 제목 글쓴이 날짜 조회 수
246 [Gemini] ajax 와 fetch 의 차이 황제낙엽 2025.01.04 3419
245 [검토 완료] 디바이스 카메라로 촬영한 사진을 서버에 업로드하기 샘플 황제낙엽 2024.11.21 3987
244 브라우저에서 이미지를 편집(crop 등) 할 수 있는 오픈소스 Cropper.js 황제낙엽 2024.11.16 3842
243 [ChatGPT] json data 의 정렬 [1] 황제낙엽 2024.07.23 3352
242 DOMContentLoaded 이벤트와 window.onload 이벤트 황제낙엽 2024.07.15 3669
241 fetch() 사용 예제들 황제낙엽 2024.07.09 3380
240 [Copilot] Vanilla JavaScript에서 외부 스크립트 파일에 정의된 함수들을 로드 황제낙엽 2024.06.21 3758
239 [Copilot] ES6 모듈(module) 문법 황제낙엽 2024.06.21 3805
238 [Copilot] JSON 객체 내부 데이터를 순회하면서 조회하는 코드 황제낙엽 2024.06.02 3270
237 [Copilot] JavaScript로 서버에 특정 값을 POST 방식으로 전달하고 응답을 기다리지 않고 바로 종료 황제낙엽 2024.05.31 3615
236 json 데이터 내의 변수명에 prefix 로 type 표현하기 황제낙엽 2024.04.15 3361
235 fetch() 함수 사용 예제 file 황제낙엽 2023.11.23 3605
234 현재 document 의 host 와 port 를 얻는 방법 황제낙엽 2023.10.03 4209
233 (Bard) FileReader 로 여러개의 파일을 read 하는 법 file 황제낙엽 2023.08.23 3660
232 How to build a file upload service with vanilla JavaScript file 황제낙엽 2023.08.22 3715
231 (Bard) JavaScript로 JSON 배열을 작성하는 방법 황제낙엽 2023.08.21 3672
230 모바일 브라우저에서 file input element 를 이용하여 여러장의 이미지를 서버에 전송하려 할때 [1] 황제낙엽 2023.08.21 3703
229 navigator.mediaDevices 황제낙엽 2023.08.21 3798
228 Barcode Detection API 황제낙엽 2023.08.06 3854
227 정규식을 이용한 이메일 검증 스크립트 file 황제낙엽 2023.06.25 2894