hahahia

실습2 본문

Web Programming/JavaScript

실습2

hahahia 2012. 3. 28. 12:27

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

 <head>

  <title> New Document </title>

  <meta name="Generator" content="EditPlus">

  <meta name="Author" content="">

  <meta name="Keywords" content="">

  <meta name="Description" content="">

  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

 </head>

<script type="text/JavaScript">

function changeSub()

{

bigObj = document.getElementById("big");

var subMenu;

switch(bigObj.selectedIndex)

{

case 0 : subMenu = ["소나타", "아반떼", "K5", "K9"];

break;

case 1 : subMenu = ["pc", "tablet pc", "smart phone"];

break;

case 2 : subMenu = ["청바지", "타이즈", "티셔츠"];

break;

}

// 기존 목록상자의 내용 제거

var medObj = document.getElementById("med");

for(i=medObj.length; i>=0; i--)

{

medObj.remove(i);

}

// 새롭게 정의한 내용 추가

for(i=0; i<subMenu.length; i++)

{

var newnode = document.createElement("OPTION");

newnode.innerText = subMenu[i];

medObj.appendChild(newnode);

}

}

</script>

 <body>

 <SELECT id="big" onChange="changeSub()">

 <OPTGROUP label="대분류">

 <OPTION value="자동차">자동차</OPTION>

 <OPTION value="컴퓨터">컴퓨터</OPTION>

 <OPTION value="옷">옷</OPTION>

 </SELECT>

 <SELECT id="med">

 <OPTGROUP label="중분류">

 </SELECT>

 </body>

</html>

Comments