Answers for "value of select tag in javascript"

6

get selected value of dropdown in javascript

<body>
   
   <select id="list" style="padding: 10px;" onchange="getSelectValue();">
     <option value="js">JavaScript</option>
     <option value="php">PHP</option>
     <option value="c#">Csharp</option>
     <option value="java">Java</option>
     <option value="node">Node.js</option>
   </select>
   
    <script>
        function getSelectValue()
        {
            var selectedValue = document.getElementById("list").value;
            alert(selectedValue);
        }
        getSelectValue();
    </script>
 </body>
Posted by: Guest on June-12-2020
0

get value from select tag

<form>
  Select your favorite fruit:
  <select id="mySelect">
    <option value="apple">Apple</option>
    <option value="orange">Orange</option>
    <option value="pineapple">Pineapple</option>
    <option value="banana">Banana</option>
  </select>
</form>

<script>
function myFunction() {
  var x = document.getElementById("mySelect").value;
  console.log(x);
}
</script>
Posted by: Guest on July-04-2021

Code answers related to "value of select tag in javascript"

Code answers related to "Javascript"

Browse Popular Code Answers by Language