How to select multiple options in a dropdown list with JavaScript?

HTMLJavascriptProgramming Scripts

To select multiple options in a drop-down list, use the multiple properties. It allows you to select more than one option while pressing CTRL key.

Example

You can try to run the following code to learn how to select more than one options at once in a dropdownlist.

Live Demo

<!DOCTYPE html>
<html>
   <body>
      <form id="myForm">
         <select id="mySelect">
            <option>One</option>
            <option>Two</option>
            <option>Three</option>
         </select>
         <input type="button" onclick="multipleFunc()" value="Select multiple options">
      </form>
      <p>Press CTRL and click above button to select multiple options at once.</p>
      <script>
         function multipleFunc() {
            document.getElementById("mySelect").multiple = true;
         }
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 13:14:11
Advertisements