Getting multiple values from a select input element

When you need to retrive several values from a select with the attribute MULTIPLE

Date 8 mars 2009
Copy and paste this script between the javascript tags

function doShow()
var users=document.forms["myForm"].elements["users"];       
var selectedUsers=getSelections(users);       

for(i=0;i < selectedUsers.length;i++)

// returns selected options elements only
function getSelections(select)
var options = select.options,sOptions = [],opt, k=0;      

while(opt = options[k++])
sOptions[sOptions.length] = opt;    

return sOptions

And in the Html body within a form tag:

select name="users" multiple="multiple" size="5"

with some options

and then a submit button with a call to the function in the onclick event:

input type="submit" name="submit" value="submit" onClick="javascript:doShow();"