Click here to Skip to main content
11,414,516 members (69,731 online)
Rate this: bad
good
Please Sign up or sign in to vote.
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 2:38am
Edited 29-Sep-12 4:09am
v3

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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 at 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
0 Sergey Alexandrovich Kryukov 9,130
1 OriginalGriff 7,477
2 Maciej Los 3,710
3 Abhinav S 3,298
4 Peter Leow 3,084


Advertise | Privacy | Mobile
Web01 | 2.8.150427.2 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100