title: Javascript Get Values from Multiple Select Option Box
body: <p>This one is driving me nuts. It’s got to be something simple and stupid that I am overlooking. 
  I have a multiple select box in a form. I am just trying to get the values that are selected. In my loop, if I use alert then I have no problem. As soon as try to concatenate the values I get the error ‘SelBranch[...].selected' is null or not an object</p>
  
  <pre><code>      &lt;form name="InventoryList" method="post" action="InventoryList.asp"&gt;
            &lt;select name="SelBranch" class="bnotes" size="5" multiple="multiple"&gt;
            &lt;option value="All"&gt;All&lt;/option&gt;
            &lt;option value="001 Renton"&gt;001 Renton&lt;/option&gt;
            &lt;option value="002 Spokane"&gt;002 Spokane&lt;/option&gt;
            &lt;option value="003 Missoula"&gt;003 Missoula&lt;/option&gt;
            &lt;option value="004 Chehalis"&gt;004 Chehalis&lt;/option&gt;
            &lt;option value="005 Portland"&gt;005 Portland&lt;/option&gt;
            &lt;option value="006 Anchorage"&gt;006 Anchorage&lt;/option&gt;
            &lt;option value="018 PDC"&gt;018 PDC&lt;/option&gt;
            &lt;/select&gt;
  
           &lt;input type="button" name="ViewReport" value="View" class="bnotes" onclick="GetInventory();"&gt;
  
     &lt;/form&gt;
  
  
     &lt;script language="JavaScript"&gt;
         function GetInventory()
         {
           var InvForm = document.forms.InventoryList;
           var SelBranchVal = "";
           var x = 0;
  
           for (x=0;x&lt;=InvForm.SelBranch.length;x++)
           {
              if (InvForm.SelBranch[x].selected)
              {
               //alert(InvForm.SelBranch[x].value);
               SelBranchVal = SelBranchVal + "," + InvForm.SelBranch[x].value;
              }
           }
           alert(SelBranchVal);
         }
  
  
    &lt;/script&gt;
  </code></pre>