夏期劇場
夏期劇場

Reputation: 18325

HTML Select Box show as Multiple, but to Disable Multiple Selection?

I needed to have:

Then it is showing correctly as:

<select id="gagaga" multiple>
    <option>A</option>
    <option>B</option>
    <option>C</option>
</select>

How can i make it non-multiple selectable (to allow only 1 selection)?

Upvotes: 22

Views: 19529

Answers (4)

Jai
Jai

Reputation: 74738

you need to provide size to it:

<select id="gagaga" size='3'>
   <option>A</option>
   <option>B</option>
   <option>C</option>
</select>

and just remove the multiple there, It will enable you to select just one option in the list.

Upvotes: 0

Avio
Avio

Reputation: 29

You can use this:

<html>
<body>
<select id="gagaga" size="3">
   <option>A</option>
   <option>B</option>
    <option>C</option>
</select>
</body>
</html>

Upvotes: 0

ameya rote
ameya rote

Reputation: 1114

Use this size="3"

<!DOCTYPE html>
<html>
<body>
<select id="gagaga" size="3">
    <option>A</option>
    <option>B</option>
    <option>C</option>
</select>
</body>
</html>

If the value of the size attribute is greater than 1, but lower than the total number of options in the list, the browser will add a scroll bar to indicate that there are more options to view.

Upvotes: 27

adi rohan
adi rohan

Reputation: 806

Do not use the multiple attribute instead set the size for it .

Quoted from w3schools:

The size attribute specifies the number of visible options in a drop-down list.

If the value of the size attribute is greater than 1, but lower than the total number of options in the list, the browser will add a scroll bar to indicate that there are more options to view.

Upvotes: 2

Related Questions