It’s working normally, it turns out the user needs to keep the key Ctrl pressed while selecting items. It also works by holding down the mouse button while passing the cursor over the options. Test:
/* somente visualização */
select{border: 2px solid #ccc;width:250px;height:200px}
<select multiple name='sites[]'>
<option value='site-a'>site a</option>
<option value='site-b'>site b</option>
<option value='site-c'>site c</option>
<option value='site-d'>site d</option>
</select>
Another solution may be to use a plugin like Multiselect:
The question asked in the comments:
I need to create a list where the user can select more than one option, so it would be possible to create a checkbox list with a scroll bar?
That question on Stackoverflow-en quotes a plugin called "Multiselect Widget UI", on that page there are some examples of what it is possible to do with it.
In my opinion it is not even necessary to include a script just to display a 'check'. A simple CSS-only implementation:
/* somente visualização */
select{border: 2px solid #ccc;width:250px;height:200px}
option:before { content: "☐ " }
option:checked:before { content: "☑ " }
<select multiple name='sites[]'>
<option value='site-a'>site a</option>
<option value='site-b'>site b</option>
<option value='site-c'>site c</option>
<option value='site-d'>site d</option>
<option value='site-e'>site e</option>
</select>
The great advantage is that customization becomes easier even if you have little knowledge in CSS. To illustrate, an example using two images: and for selected options:
option:before{ margin-right: 5px;content:url('http://i.stack.imgur.com/SHKSN.png') }
option:checked:before { content: url('http://i.stack.imgur.com/sjCFU.png') }
<select multiple name='sites[]'>
<option value='site-a'>site a</option>
<option value='site-b'>site b</option>
<option value='site-c'>site c</option>
</select>
I tested the code and it worked. You are using the control to select more than one option?
– Arthur Menezes
I didn’t know I should use control; Now that I know, this raises a question, I need to create a list where the user can select more than one option, so it would be possible to create a checkbox list with a scrollbar (the list is quite large)
– Ricardo
Although your HTML works, I would still suggest putting the text inside the tags
option
, as:<option value="site-2" selected>SITE</option>
– sergiopereira