Select more than one item with the select tag

Asked

Viewed 107 times

0

I’m having a problem, the html tag allows the user to select only one option from the list, however I need to select more than one select item, how to do this using only JS? I need to select which days of the week to hold an event, such as an alarm.

<select name="diasSemana">
   <option value="1">Segunda</option>
   <option value="2">Terça</option>
   <option value="3">Quarta</option>
   <option value="4">Quinta</option>
   <option value="5">Sexta</option>
   <option value="6">Sábado</option>
   <option value="7">Domingo</option>
</select>

  • 2

    Vitor, you can select more than one element in select, without javascript, just declare the property Multiple within the select, you can read more here: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select

1 answer

3


You can create a normal select with the Multiple tag and the user selects with Ctrl the multiple options in your select, when passed by post, will receive something like:

<form action="/action_page.php">
  <select name="opcoes" multiple>
    <option value="opcao1">opcao1</option>
    <option value="opcao2">opcao2</option>
    <option value="opcao3">opcao3</option>
    <option value="opcao4">opcao4</option>
  </select>
  <input type="submit">
</form>

opcoes=opcao1&opcoes=opcao2&opcoes=opcao3

There is documentation about multiselect in w3schools, give a glance: https://www.w3schools.com/tags/att_select_multiple.asp

  • I saw this option, I just found it annoying to use, having to press control to select more than one, many users do not know it, including I did not know kkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.