Allow multiple selection in a drop-down list:
document.getElementById("mySelect").multiple = true;
Click the button to allow multiple selection.
Hold Ctrl or Shift to select more than one option.
<!DOCTYPE html> <html> <body> <form> <select id="mySelect" size="4"> <option>Apple</option> <option>Pear</option> <option>Banana</option> <option>Orange</option> </select> </form>/*from w w w.j a v a 2 s.co m*/ <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>
The multiple property sets or gets whether more than one item can be selected from a drop-down list.
The multiple property accepts and returns a boolean type value,
Property Values
Value | Description |
---|---|
true | Multiple selection is allowed |
false | Default. Multiple selection is not allowed |
The multiple property returns true if multiple selection in the drop-down list is enabled, otherwise it returns false.