Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SELECT element in the multiple selection display style without allowing multiple selection

Tags:

html

I want to have a element that displays in the multiple selection display style (it --the box instead of the drop down), but only allows you to select on thing at a time. Is that possible?

like image 600
Sam Lee Avatar asked May 22 '09 21:05

Sam Lee


3 Answers

This will display a listbox-style select element that allows only one selected item at a time:

<select size="3">
    <option>1</option>
    <option>2</option>
    <option>3</option>
</select>

The size atttribute will control how many rows that are visible in the control. If you want to allow multiple items to be selected, add the multiple attribute to the select element:

<select size="3" multiple="multiple">
like image 197
Fredrik Mörk Avatar answered Oct 18 '22 00:10

Fredrik Mörk


The manner in which SELECT elements are rendered is implementation-dependent. The fact that in most browsers 'multiple="1"' gets you a (possibly scrolling) box of options and multiple="0" gets you a drop-down box is coincidence.

There is no standard for saying "I want a list box that only allows one option to be selected".

See also:

http://www.w3.org/TR/html401/interact/forms.html#h-17.6

like image 24
Nicholas Knight Avatar answered Oct 18 '22 02:10

Nicholas Knight


You could write js that would deselect any extra selections onclick

like image 29
branchgabriel Avatar answered Oct 18 '22 02:10

branchgabriel