Determining the Values of Multiselection Lists : List « Form Control « JavaScript DHTML






Determining the Values of Multiselection Lists

<html>
<head>
<script language = "JavaScript">
     function showSelection(objectName) {
          var list = ""
          for (var i=0; i<objectName.length; i++) {
               if (objectName.options[i].selected) {
                    list += objectName.options[i].text + "<p>"
               }
          }
          alert(list)
     }
   
</script>
</head>
<body>
    <form name="form1">
      Pick Your Favorite Songs From the List:<p>
        <select NAME="songs" SIZE=5 MULTIPLE>
            <option>AA</option>
            <option>B</option>
            <option>C</option>
            <option>D</option>
            <option>E</option>
            <option>F</option>
            <option>G</option>
            <option>H</option>
            <option>I</option>
            <option>J</option>
        </SELECT><p>
      <input type=button value="Show Selection" onClick="showSelection(this.form.songs)">
    </form>
</body>
</html>

           
       








Related examples in the same category

1.Determining the Value or Text of the Selected Option
2.Determining the Size of the List
3.Selection List Event Handling
4.Cycling through a Multiple-Selection List