Click here to Skip to main content
Sign Up to vote bad
good
See more: Beginner
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 )
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 29-Sep-12 1:38am
Edited 29-Sep-12 3:09am


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:
var arr = "SelectedValues = ";
for(int i=0; i < document.f1.s1.options.length; ++i)
{
  arr= arr + "," + document.f1.s1.options[i].value;
  // Use arr
}
  Permalink  
Comments
Marcus Kramer - 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)

  Print Answers RSS
Your Filters
Interested
Ignored
     
0 Christian Graus 500
1 Ron Beyer 316
2 Tadit Dash 253
3 samadhan_kshirsagar 229
4 OriginalGriff 198
0 Sergey Alexandrovich Kryukov 7,061
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,370
4 CPallini 3,034


Advertise | Privacy | Mobile
Web02 | 2.6.130619.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid