Javascript tutorial: 2 How to get all selected values of a multiple select box?

In this Javascript tutorial learn  How to get all selected values of a multiple select box, Get selected values of Multiple Selected Options in Select Box On this page we show how to use JavaScript to get a list of selected options in a select-multiple type select box.



 <!DOCTYPE html>
    <html>
    <script>
    function getMultipleSelectedValue()
    {
      var t=document.getElementById("tutorial_1");
      for (var i = 0; i < t.options.length; i++) {
         if(t.options[i].selected ==true){
              alert(t.options[i].value);
          }
      }
    }
    </script>
    </head>
    <body>
    <select multiple="multiple" id="tutorial_1">
      <option value="tutorial 1">tut 1</option>
      <option value="tutorial 2">tut 2</option>
      <option value="tutorial 3">tut 3</option>
      <option value="tutorial 4">tut 4</option>
    </select>
    <input type="button" value="Submit" onClick="getMultipleSelectedValue()"/>
    </body>
    </html>

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...