Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I needed to have:

  • A html <select> box showing as a vertically expanded box (not a Dropdown). So i set it as multiple.

Then it is showing correctly as:

<select id="gagaga" multiple>
    <option>A</option>
    <option>B</option>
    <option>C</option>
</select>
  • Then how can i make it non-multiple selectable? (to allow only 1 selection)
like image 229
夏期劇場 Avatar asked Jan 04 '13 10:01

夏期劇場


2 Answers

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.

like image 161
ameya rote Avatar answered Oct 15 '22 18:10

ameya rote


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.

like image 34
adi rohan Avatar answered Oct 15 '22 19:10

adi rohan