Option.defaultSelected : Option Object « Form « JavaScript Tutorial






The defaultSelected property specifies the initial option selection of the select list.

<html>
    <head>
    <title> Example of the defaultSelected property of the option object</title>
    </head>
    <body>
    <script language="JavaScript">
    <!--
    function check(myForm){
       for (var i = 0; i < document.form1.myList.length; i++) {
          if (document.form1.myList.options[i].defaultSelected == true) {
             alert("The default value is: 2");
          }
       }
    }
    -->
    </script>
    <form name=form1>
    <select name="myList" multiple>
    <option value=1>One
    <option value=2 SELECTED>Two
    <option value=3>Three
    <option value=4>Four
    </select><P>
    <input type="button" value="Get Default Value" onClick='check(this.form)'>
    </form>
    </body>
    </html>








10.9.Option Object
10.9.1.Option
10.9.2.Option.defaultSelected
10.9.3.Option.selected
10.9.4.Option.text
10.9.5.Option.value