jQuery | javascript | CSS

29.JavaScript - SelectedIndex (드롭다운리스트)

Godffs 2009. 8. 12. 00:08
반응형
selectedIndex : 드롭다운리스트 컨트롤의 현재 선택된 인덱스 값을
                       반환하는 예제입니다.


<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="APS.NET">ASP.NET</option>
        <option value="Silverlight">Silverlight</option>
    </select>
   
    <input type="button" value="확인" onclick="CheckSelect();" />
</body>
</html>
반응형