Click here to Skip to main content
12,450,918 members (51,890 online)
Rate this:
 
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 1:38am
Updated 29-Sep-12 3: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 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
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 29 Sep 2012
Copyright © CodeProject, 1999-2016
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