Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

questions about the <select> list

Status
Not open for further replies.

ffej2ffej

Programmer
Oct 8, 2005
9
US
The book I have (JavaScript Second Edition by Don Gosselin) says something about the <select> tag in JavaScript that is either incorrect or I'm not using it properly. According to the book, if the size attribute of the select list is either not specified or set to 1, the list will be a drop-down type list. However, if I want the user to be able to select multiple choices from the list,
Code:
multiple=true
all this goes out the window. If multiple is allowed, the list appears large enough to show all choices at once, regardless of the size I've specified. If there is a way to make the list only as tall as one entry and still allow multiple selections, I'd like to know how.

Thank you
 
>If there is a way to make the list only as tall as one entry and still allow multiple selections

Size 1 or else, at the second select
[a] consecutive after/before the first selected: {enter}+{left click};
individually selected as well as the first: {control}+{left click}.

 
If you're only using HTML 4, as opposed to XHTML 1.0, the [tt]multiple[/tt] attribute does not have an equal sign and a value. You just put it there like this
Code:
<select name="stuff" multiple>
ref: HTML 4.01 spec

If you do want to be compliant with XHTML 1.0, the "minimized" syntax of boolean attributes isn't allowed, so you must put the same word after the equal sign as before the equal sign like this:
Code:
<select name="stuff" multiple="multiple">
ref: XHTML 1.0 spec. ... but I'm sure [tt]multiple=true[/tt] works.

As tsuji mentioned, the attribute is [tt]size[/tt] as referenced in the HTML 4 spec., but I recommend using CSS to set the size of your element in a separate stylesheet. I think that the height of a single row in a select box is 1.5em. That way you can optionally set the size of multiple select boxes at once or any other attributes you want...

style.css:
Code:
select {
    height: 1.5em;
}

page.html
Code:
<select name="stuff" id="stuff" multiple="multiple">
<!-- more stuff below here -->

One thing to be aware of, though, is that you might lose your down- and up-arrows for scrolling your list box if you make it too small.

--
-- Ghodmode
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top