Select multiple values ​​from the drop-down list

I have a dropdown list containing all ontacts on a mobile phone. I want to select several contacts at the same time.

When I was working on regular html and 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 skipped and it just stops, this statement is:

  "selObj.options[i].selected" 

seems strange for mobile!

+6
source share
1 answer

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 changed this:

  if (selObj.options[i].selected) 

:

  if(selObj.options[i].selected==true) 
+4
source

Source: https://habr.com/ru/post/914415/


All Articles