[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Multiple Select

Posted on 1998-10-05
8
Medium Priority
?
189 Views
Last Modified: 2012-05-04
How do I retrieve the number of items and the value of the items selected from a multiple select list box?

ie
<SELECT NAME=MULTI MULIPLE>
<OPTION ...
</SELECT>
0
Comment
Question by:obsrhayden
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
  • 2
8 Comments
 
LVL 1

Expert Comment

by:nchalasa062698
ID: 1838358
Got to use Javascript.

can write the code if you want.....
0
 

Author Comment

by:obsrhayden
ID: 1838359
Yes I'd like the code
0
 
LVL 1

Expert Comment

by:nchalasa062698
ID: 1838360
To get the number of selected values , you need to use a
for loop in the javascript to loop thru all of them and count the once that are
selected.

function find_selections(selobj)
{
   var  selectednum =0;
   for (var i=0; i<selobj.length; i++)
    { if(selobj.options[i].selected )
            selectednum++
    }
   return selectednum
}
   
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:nchalasa062698
ID: 1838361
To get the number of selected values , you need to use a
     for loop in the javascript to loop thru all of them and count the once that are
     selected.

     function find_selections(selobj)
     {
        var  selectednum =0;
        for (var i=0; i<selobj.length; i++)
         { if(selobj.options[i].selected )
                 selectednum++
         }
        return selectednum
     }
       
0
 

Author Comment

by:obsrhayden
ID: 1838362
That only answer half the question.  How do I get the values of the selected items.
Let's say a function that returns a string with the items delimited by a |.
0
 
LVL 1

Accepted Solution

by:
nchalasa062698 earned 200 total points
ID: 1838363
function find_selections2(selobj)
          {
             var  astr;
             for (var i=0; i<selobj.length; i++)
              { if(selobj.options[i].selected )
                      astr=astr+' | '+selobj.options[i].value
              }
             return astr
          }
             
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 1838364
here is sample code for you...
I think you might find this easier than the above proposed answer:


Value_Array=new Array(document.selectObjectName.options.length);
var numberSelected=0

function interpret() {

          for (var i=0; i < document.selectObjectName.options.length; i++)
          {
                    if (document.selectObjectName.options[i].selected==true)
                    {
                              Value_Array[i]=document.selectObjectName.options[i].value;
                              numberSelected++;
                    }
          }
}



This function will give you numberSelected for the number selected by user
and Value_Array (range 0..numberSelected-1) for an array of strings containing the values of the selected items.

If you get errors try moving the variable declarations inside the function but it
should work.

this should help you out.

CJ
0
 
LVL 19

Expert Comment

by:cheekycj
ID: 1838365
I didn't read the delimited by '|' part but that is easy to fix.

Instead of String Array just declare a string variable and init it to '' by:
string_var_name='';

and where I have
  Value_Array[i]=document.selectObjectName.options[i].value;
replace by
  string_var_name=string_var_name+document.selectObjectName.options[i].value+'|';
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question