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?
views:
259answers:
5
A:
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">
Fredrik Mörk
2009-05-22 21:15:59
Whether or not this works will depend entirely on the browser; the HTML standard does not specify this behavior, 'size' only applies IF the browser chooses to render a SELECT as a listbox, which it is never required to do, even if 'size' is specified (it's pretty explicit on this point).
Nicholas Knight
2009-05-22 21:42:27
The question was not "does the HTML standard include this" but rather "is it possible to get this behaviour". While you are correct that it is up to the implementation to decide this (thanks for pointing it out BTW), both IE and FF (the browsers that I have available right now for testing) have implemented this behaviour. So, is it possible? Yes. Is the behaviour guaranteed in all concievable user agents? No.
Fredrik Mörk
2009-05-22 21:50:55
A:
How about an ordered list <ol>
or unordered list <ul>
with links for the list items <li>
?
DOK
2009-05-22 21:18:19
+1
A:
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:
Nicholas Knight
2009-05-22 21:19:35