Determining the Values of Multiselection Lists : List : Form Control : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
C++
JavaScript DHTML Home »  Form Control   » [  List  ]   
 



Determining the Values of Multiselection Lists

Please note that some example is only working under IE or Firefox.


/*
JavaScript Unleashed, Third Edition
by Richard Wagner and R. Allen Wyke 

ISBN: 067231763X
Publisher Sams CopyRight 2000

*/
<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>"
               }
          }
          selWindow = window.open("""Selections""height=200,width=400")

          selWindow.document.write("<h2>You picked the following songs:</h2><p><p>")
          selWindow.document.write(list)
     }
   
</script>
</head>
<body>
    <form name="form1">
      Pick Your Favorite Songs From the List:<p>
        <select NAME="songs" SIZE=MULTIPLE>
            <option>Fortress Around Your Heart</option>
            <option>Breakfast at Tiffany's</option>
            <option>Flood</option>
            <option>The Chess Game</option>
            <option>Liquid</option>
            <option>World's Apart</option>
            <option>Ironic</option>
            <option>1979</option>
            <option>Wonderwall</option>
            <option>Standing Outside a Broken Phone Booth</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








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.