Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selection of multiple values from drop down list

I've a drop down list that contains all the ontacts on mobile. I want to select more than one contact at a time.

When I was working on regular html & JS pages I used this code:

     function loopSelected()
     {
      var txtSelectedValuesObj = document.getElementById('txtContactsName');
      var selectedArray = new Array();
      var selObj = document.getElementById('AllContacts');
      var i;
      var count = 0;
      for (i=0; i<selObj.options.length; i++) 
      {
         if (selObj.options[i].selected) {
         selectedArray[count] = selObj.options[i].value;
        count++;
       }
     }
     txtSelectedValuesObj.value = selectedArray;
  }

But when I use it on Android, then if statement is skipped & it just stops,this statement:

    "selObj.options[i].selected" 

seems strange for the mobile!

like image 262
Sana Joseph Avatar asked Apr 28 '12 13:04

Sana Joseph


People also ask

How do I create a multiple selection in a drop down list?

Go to Data –> Data Tools –> Data Validation. In the Data Validation dialogue box, within the settings tab, select 'List' as Validation Criteria. In Source field, select the cells which have the items that you want in the drop down. Click OK.

Can we do multiple selection in drop down?

Instead of limiting the drop down list to a single selection, you can use a bit of programming, combined with the data validation list, and allow multiple selections. With a few adjustments to the VBA code, you can display all the selected items across a row, or down a column, or keep them in a single cell.

How do I select multiple values in a list?

Hold the CTRL key and click the items in a list to choose them. Click all the items you want to select.


1 Answers

This worked:

    function ChooseContact(data)
    {
      var txtSelectedValuesObj = document.getElementById('txtContactsName');
      var selectedArray = new Array();
      var selObj = document.getElementById('contacts');
      var i;
      var count = 0;
      for(i=0;i<selObj.options.length;i++)
      {
        if(selObj.options[i].selected==true)
        {
         selectedArray[count] = selObj.options[i].value;
         alert(selObj.options[i].value);
         count++;
        }
      }
     txtSelectedValuesObj.value = selectedArray;
   }

I just modified this:

    if (selObj.options[i].selected) 

to this:

   if(selObj.options[i].selected==true)
like image 61
Sana Joseph Avatar answered Oct 18 '22 10:10

Sana Joseph