<SELECT multiple> - how to allow only one item selected?

simPod picture simPod · Mar 17, 2011 · Viewed 130.1k times · Source

I have a <SELECT multiple> field with multiple options and I want to allow it to have only one option selected at the same time but user can hold CTRL key and select more items at once.

Is there any way how to do it? (I don't want to remove 'multiple').

Answer

Marcos Placona picture Marcos Placona · Mar 17, 2011

Just don't make it a select multiple, but set a size to it, such as:

  <select name="user" id="userID" size="3">
    <option>John</option>
    <option>Paul</option>
    <option>Ringo</option>
    <option>George</option>
  </select>

Working example: https://jsfiddle.net/q2vo8nge/