Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

83
Visualizações
In a <select multiple> tag, how to put the values from selected <option> tags to an array?

I have this code:

<select multiple id="test">
  <option value="A">Option A</option>
  <option value="B">Option B</option>
  <option value="C">Option C</option>
  <option value="D">Option D</option>
</select>

If the user selects A and C, is there a way to put those values in an array? If the select is not multiple, I can use option = document.getElementById('test').value;. But if it's multiple then I don't know how to do it. Because we can only use one value attribute, not an array of attributes. The documentations for <option> and <select> aren't useful. There is also a similar question but I'm not sure how to apply it.

What I want is to put them into a string:

string = 'You select` + optionarray[0] + ' and ' + optionarray[1] + ' and ' + optionarray[2] + ... //until there is no more element left
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda