Javascript Reference - HTML DOM Select multiple Property








The multiple property sets or gets if the select support multiple selections.

Browser Support

multiple Yes Yes Yes Yes Yes

Syntax

Return the multiple property.

var v = selectObject.multiple 

Set the multiple property.

selectObject.multiple=true|false 

Property Values

Value Description
true|false If the drop-down list supports multiple selection
  • true - Multiple selection is allowed
  • false - Default. Multiple selection is not allowed




Return Value

A Boolean type value, true if the drop-down list supports multiple selection, otherwise false.

Example

The following code shows how to check if more than one option in a drop-down list can be selected.


<!DOCTYPE html>
<html>
<body>
<!--from w  w  w .j a va  2  s.c  o m-->
<select id="mySelect">
  <option>A</option>
  <option>B</option>
  <option>C</option>  
</select>
<button onclick="myFunction()">test</button>
<p id="demo"></p>

<script>
function myFunction() {
    var x = document.getElementById("mySelect").multiple;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows:





Example 2

The following code shows how to allow multiple selection in a drop-down list.


<!DOCTYPE html>
<html>
<body>
<!-- w w  w  .  ja va  2s.  co  m-->
<form>
<select id="mySelect" size="4">
  <option>A</option>
  <option>B</option>
  <option>C</option>
  <option>D</option>
</select>
</form>
<button type="button" onclick="myFunction()">test</button>
<script>
function myFunction() {
    document.getElementById("mySelect").multiple = true;
}
</script>
</body>
</html> 

The code above is rendered as follows: