<select id="s" multiple onchange="alert(selected())">
 <option id="a" selected>a</option>
 <option id="b">b</option>
</select><script type="text/javascript">
  function selected()
{
   var v,r;
   v=document.getElementById("s");
   v=v.options;
   for(var i=0; i<v.length; i++)
     if(v[i].selected)
       r += v[i].value +",";
       // or r+=v[i].id
       // or r+=v[i].innerText   return r;
}alert (selected());
</script>

解决方案 »

  1.   

    <FORM ACTION="" NAME="theFindForm" onsubmit="getVal();return false">
    <select name='selectableIDList' multiple style="WIDTH: 100px" >
     <option value="111">A</option>
     <option value="222">B</option>'
     <option value="333">C</option>
     <option value="444">D</option>
     <option value="555">E</option>
     </select>
      <input type="submit" name="setDU">
          </FORM>
    用JAVASCRIPT取出'selectableIDList'中的Value值
      

  2.   

    function selected()
    {
       var v,r;
       v=document.getElementById("s");
       v=v.options;
       for(var i=0; i<v.length; i++)
         if(v[i].selected)
         {
           r += v[i].value;
           if(i!=v.length-1)
             r +=",";
             //以,分隔不同的值
         }
       return r;
    }
      

  3.   

    //取出所有的值,以,分隔
    function selected2()
    {
       var v,r;
       v=document.getElementById("selectableIDList");
       v=v.options;
       for(var i=0; i<v.length; i++)
      {
           r += v[i].value;
           if(i!=v.length-1)
             r +=",";
             //以,分隔不同的值
      }
       return r;
    }
      

  4.   

    前一个有bug,这个是正确的
    //取出被选中的值,以,分隔
    function selected()
    {
       var v,r;
       v=document.getElementById("selectableIDList");
       v=v.options;
       r=new Array();
       j=0;
       for(var i=0; i<v.length; i++)
         if(v[i].selected)
           r[j++]=v[i].value;
       r.join(",");
       return r;
    }