Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: (untagged)
Hi everyone,

How to get multiple values from a list using java script? I can select multiple values but i got only a single value. pls help me. (this is the code i have )
JavaScript
var arr=document.f1.s1.options[document.f1.s1.selectedIndex].value;

(here f1 is the form name and s1 is the list name)

with regards
shajna v.Akbar
Posted
Updated 29-Sep-12 3:09am
v3

1 solution

How to get multiple values from a list using java script
The code that you have above is for a specific index. Create a for loop and loop over the index. Get all the values you seek.
Ex:
JavaScript
var arr = "SelectedValues = ";
for(int i=0; i < document.f1.s1.options.length; ++i)
{
  arr= arr + "," + document.f1.s1.options[i].value;
  // Use arr
}
 
Share this answer
 
Comments
fjdiewornncalwe 29-Sep-12 9:27am    
+5. Very nice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900