3초기억력

JavaScript - 동적 셀렉트 본문

플밍_기타

JavaScript - 동적 셀렉트

잠수콩 2008. 11. 18. 10:25



<HTML>
<HEAD>
<TITLE> 동적 select </TITLE>
</HEAD>
<script language="javascript">
function food_view(choice_value)
{
 init_value=new Array(new Array("떡볶이","김밥","순대","라면"), new Array("비빔밥","불고기","된장찌개"), new Array("짜장면","짬뽕"), new Array("돈까스"));

 if(choice_value!="")
 {
  document.f1.food_menu.options.length=1; //초기화
  loop_count=init_value[choice_value].length;

  for(i=0;i<loop_count;i++)
  {
   new_option=document.createElement("OPTION");
   new_option.text=init_value[choice_value][i];
   new_option.value=init_value[choice_value][i];
   document.f1.food_menu.add(new_option);
  }
 }
 else
 {
  document.f1.food_menu.options.length=1; //초기화
 }
}
</script>

<BODY>
<form name="f1">
<select name="food_type" onchange="food_view(this.value)">
<option value="">선택</option>
<option value="0">분식</option>
<option value="1">한식</option>
<option value="2">중식</option>
<option value="3">양식</option>
</select>
<select name="food_menu">
<option value="">선택</option>
</select>

</form>
</BODY>
</HTML>

Comments