Please Enable JavaScript!
Gon[ Enable JavaScript ]

Select 박스 선택시 그 값을 알수 있는 코드 예제

웹 프로그래밍/자바스크립트
반응형

다음 예제는 select 에서 5번을 선택하면 입력박스로 커서가 이동하고

다른 번호를 선택하면 입력 박스에서 커서가 없어지는 예제이다.

선택한 값은 this.options[this.selectedIndex].value 얻어올수 있다.

<html>

<head>

<script language='javascript'>

<!--

       function set_txt1(val){

              alert(val);

              if (+val == 5){

                     document.selectdb.txt1.focus();

              }else{

                     document.selectdb.txt1.blur();

              }

       }

-->

</script>

</head>

<body>

  <form name="selectdb">

  <select name="changedb"
   onchange="set_txt1(this.options[this.selectedIndex].value)">

    <option value="01">01</option>

    <option value="02">02</option>

    <option value="05">05</option>

    <option value="06">06</option>

  </select>

  <input type="text" name="txt1" size="5" maxlength="5" value="20">
</form>

<input type="button" name="simabutton"

   onclick='window.location="view-source:"+window.location.href'>

</body>

</html>


반응형
Posted by 녹두장군1
,