콤보박스는 여러개의 항목 중에서 원하는 것을 하나만 선택하는 컨트롤이다.
문법
<select name="값의 이름" multiple="multiple">
<option value="선택될 경우 name의 값이 됨" selected="selected">값의 대한 표시값</option>
... option 반복
</select>
- multiple : 이 속성의 값을 multiple로 지정하면 여러개의 항목을 선택할 수 있은 컨트롤이 됨.
예제
- comboboxexample.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
</head>
<body>
<form action="example_receive_single.php" method="POST">
관심사 : <br />
<select name="interest">
<option value="programming">프로그래밍</option>
<option value="design" selected="selected">디자인</option>
<option value="planning">기획</option>
</select>
<input type="submit" />
</form>
</body>
</html>
- example_receive_single.php
<html>
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head>
<body>
당신의 관심사는? <?=$_POST['interest']?>
</body>
</html>
예제 설명
예제를 html 파일에 코딩하여 실행하면 아래 그림과 같은 웹페이지가 나온다.
처음에 디자인에 selected 옵션이 설정되어 디자인으로 나와있고, 스크롤을 내려서 다른 항목으로 바꿀수 있다. 원하는 항목을 선택 후 제출 버튼을 누르면 라디오 버튼에서 했던 것과 같은 결과가 나온다.
'Programming > HTML' 카테고리의 다른 글
파일 업로드 (0) | 2017.12.12 |
---|---|
체크박스 (0) | 2017.12.12 |
라디오 버튼 (0) | 2017.12.11 |
비밀번호, hidden data, textarea (0) | 2017.12.11 |
폼(form), 텍스트 입력 (0) | 2017.12.11 |