29. 드롭다운리스트체크(selectedIndex 사용)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript">
function CheckSelect() {
if (document.getElementById("lstFavorite").selectedIndex == 0) {
alert("관심사항을 선택하시오.");
document.getElementById("lstFavorite").focus();
}
else {
window.alert("당신의 관심사항 : " + document.getElementById("lstFavorite").value);
}
}
</script>
</head>
<body>
관심사항<br />
<select id="lstFavorite">
<option value="">- 선택 -</option>
<option value="C#">C#</option>
<option value="ASP.NET">ASP.NET</option>
<option value="Sliverlight">Silverlight</option>
</select>
<input type="button" value="확인" onclick="CheckSelect();" />
</body>
</html>