tags:

views:

259

answers:

5

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?

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
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
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
A: 

What about a ListBox?

Robert Harvey
A: 

How about an ordered list <ol> or unordered list <ul> with links for the list items <li>?

DOK
+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:

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

Nicholas Knight
+1 Important stuff to keep in mind.
Fredrik Mörk
A: 

You could write js that would deselect any extra selections onclick

mugafuga