How do I read which items have been selected in a multiple listbox

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    How do I read which items have been selected in a multiple listbox

    After the user has made their selection from a multiple select box how can I read the options array to see which items were selected

    Code:
       
    <select
      id  ="PHASECODE"
      name="PHASECODE"
      multiple="multiple"
      size="10"
      onblur="readSelect();"
    >
     <option value="10">10. Drilling</option>
     <option value="15">15. Layout</option>
     <option value="30">30. Geotechnical Eng.</option>
     <option value="40">40. Enviromental</option>
     <option value="50">50. Design Services</option>
     <option value="60">60. Construction Material Eng.</option>
     <option value="70">70. Concrete and Asphalt Lab.</option>
     <option value="80">80. Soils Lab.</option>
     <option value="92">92. Maint. Shop Activites</option>
    </select>
    
    
    function readSelect()
    {
    //how do I determine which items were selected.
    }
  • Claus Mygind
    Contributor
    • Mar 2008
    • 571

    #2
    Ok I think I got it figured out.

    Code:
    function readSelect()
    {
     for (var i = 0; i < document.getElementById("PHASECODE").options.length; i++ )
     {
      if ( document.getElementById("PHASECODE").options[i].selected )
      {
       alert(document.getElementById("PHASECODE").options[i].value);
      }
     }
    }

    Comment

    Working...