'동적셀렉트'에 해당되는 글 1건

  1. 2008.11.18 JavaScript - 동적 셀렉트 by 잠수콩



<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>

저작자 표시 비영리 변경 금지
신고
Posted by 잠수콩