Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Single-selectable listview in pure HTML/CSS?

By default a <select> element is a dropdown menu which I don’t want: I want to display the full list. This is possible with multiple:

<select name="pets" multiple size="5">
<option>dog</option>
<option>cat</option>
<option>hamster</option>
<option>bird</option>
<option>donkey</option>
<option>fish</option>
</select>

but then obviously the user can select multiple elements.

How to have a full list view (like with multiple, i.e. no dropdown menu), but have only one possible selected element?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Use the size attribute which takes the number of items you want to display and set it to the number of options you have (6) in order to get the full list view. Since you only want to allow 1 item to be selected, also remove the attribute multiple from the select element.

<select name="pets" size=6>
  <option>dog</option>
  <option>cat</option>
  <option>hamster</option>
  <option>bird</option>
  <option>donkey</option>
  <option>fish</option>
</select>

Check mdn for more information about the available attributes for the select element.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading