Front-Html/Javascript

javascript 배열을 이용한 select box 2개 연결

seongsland 2010. 4. 9. 16:08
<script>
 // var test = (0,0);
 var step1 = 5;

test = new Array(step1);
val = new Array(step1);
for(i=0;i<test.length;i++) {
 test[i] = new Array();
 val[i]  = new Array();
}

 test[1][0] = "젠장111";
 val[1][0] = "http://naver.com";
 test[1][1] = "펄111";
 val[1][1] = "http://yahoo.com";
 test[2][0] = "젠장222";
 val[2][0] = "http://paran.com";
 test[2][1] = "펄222";
 val[2][1] = "http://daum.com";

  function fuck(obj) {
 var ta  =  d0cument.aaa;
 ta.t2.length  = test[obj.selectedIndex].length+1;
 ta.t2[0].text = '선택';
 for(var i=0;i<test[obj.selectedIndex].length;i++) {
  ta.t2[i+1].text = test[obj.selectedIndex][i];
  ta.t2[i+1].value = val[obj.selectedIndex][i];
 }
  }

  function fuckU(turl) {
 location.href=turl.value;
  }
  </script>
  <form name="aaa">
  <select name = "t1" onchange=fuck(this);>
 <option value="">골라~</option>
 <option value="1">골라~1</option>
 <option value="2">골라~2</option>
  </select>
  <select name = "t2" onchange=fuckU(this);>
  <option value="">선택</option>
  </select>
  </form>