본문 바로가기
JAVASCRIPT/<select> 의 value 값 체크

자바스크립트로 select box (<select>) option value 값 체크

by 정윤재 2009. 2. 23.

<%@ page language="java" contentType="text/html; charset=EUC-KR"
    pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "
http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Insert title here</title>
<script language="javascript">
function sub(){

  var se= document.getElementsByName("se");

    var selectedtext;
  for(j=0;j<se.length;j++){
     
     for(i=0;i<se[j].options.length;i++){
             if(se[j].options[i].selected==true){
                     selectedtext= se[j].options[i].value;
                     break;
             }
     }
     alert(selectedtext);
  }
//일부러 여러개의 select 박스로 했다.

//복잡한것을 좋아하는게 아니라, 동적 table 변경으로 추가시에도 select 박스 체크가 가능하도록
//경우의 수를 만들었다.
  
}
</script>
</head>
<body>
<form name="form">
 <table border="1">
  <tr>
   <td>
    <select name="se">
     <option value="">===</option>
     <option value="1">1</option>
     <option value="2">2</option>
    </select>
   </td>
  </tr>
  
  <tr>
   <td>
    <select name="se">
     <option value="">===</option>
     <option value="1">1</option>
     <option value="2">2</option>
    </select>
   </td>
  </tr>
  
  <tr>
   <td>
    <input type="button" value="check" onClick="sub()">
   </td>
  </tr>
  
 </table>
</form>

</body>
</html>


댓글