Select size Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

The size property sets or gets the size attribute of a drop-down list, which controls the number of visible options in a drop-down list.

Set the size property with the following Values

Value Description
number Sets the number of visible options in a drop-down list.

Return Value

A Number, representing the number of visible options in the drop-down list

The following code shows how to change the number of visible options in a drop-down list:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<select id="mySelect" size="1">
  <option>Cat</option>
  <option>Dog</option>
  <option>Horse</option>
  <option>A</option>
  <option>B</option>
  <option>C</option>
  <option>D</option>
</select>/*from w  ww  . ja  v  a  2 s. com*/

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {
     document.getElementById("mySelect").size = "4";
}
</script>

</body>
</html>

Related Tutorials