Click here to Skip to main content
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 DamithSL 295
1 OriginalGriff 285
2 Sergey Alexandrovich Kryukov 157
3 Afzaal Ahmad Zeeshan 154
4 Peter Leow 115
0 OriginalGriff 7,510
1 DamithSL 5,494
2 Sergey Alexandrovich Kryukov 4,954
3 Maciej Los 4,936
4 Kornfeld Eliyahu Peter 4,514


Advertise | Privacy | Mobile
Web04 | 2.8.141223.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2014
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