반응형
// 셀렉트 박스 옵션 사이에 있는 텍스트 값을 가져온다.
options[target.seletedIndex].text

// 셀렉트 박스 value 의 값을 가져온다.
options[target.selectedIndex].value

 

예제

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<select name="selectBox" id="selectBox">
		<option value="가" selected>A</option>
		<option value="나">B</option>
		<option value="다">C</option>
	</select>

</body>

<script type="text/javascript">
	var target = document.getElementById("selectBox");
	alert('선택된 옵션 text 값=' + target.option[target.selectedIndex].text); // 옵션 text 값
	alert('선택된 옵션 vlaue 값=' + target.options[target.selectedIndex].value); // 옵션 value 값
</script>
</html>

예제 결과화면

반응형

+ Recent posts