Select multiple Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

The multiple property sets or gets whether more than one option/item can be selected from a drop-down list.

Set the multiple property with the following Values

Value Description
true|false Sets whether more than one option in a drop-down list can be selected

Return Value

A Boolean, returns true if multiple selection in the drop-down list is enabled, otherwise it returns false

Allow multiple selection in a drop-down list:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form>
<select id="mySelect" size="4">
  <option>CSS</option>
  <option>HTML</option>
  <option>SQL</option>
  <option>Javascript</option>
</select>/*from  w  w w. ja  v a2 s  .c o  m*/
</form>

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

<p id="demo"></p>

<script>
function myFunction() {
    document.getElementById("mySelect").multiple = true;
    document.getElementById("demo").innerHTML = "You can now select multiple options.";
}
</script>

</body>
</html>

Related Tutorials