get value select javascript

Solutions on MaxInterview for get value select javascript by the best coders in the world

showing results for - "get value select javascript"
Ugo
08 Aug 2020
1 <body>
2   
3   <select id="list" style="padding: 10px;" onchange="getSelectValue();">
4     <option value="js">JavaScript</option>
5     <option value="php">PHP</option>
6     <option value="c#">Csharp</option>
7     <option value="java">Java</option>
8     <option value="node">Node.js</option>
9   </select>
10   
11    <script>
12        function getSelectValue()
13        {
14            var selectedValue = document.getElementById("list").value;
15            alert(selectedValue);
16        }
17        getSelectValue();
18    </script>
19 </body>
Kaleigh
28 Apr 2018
1<select id="ddlViewBy">
2  <option value="1">test1</option>
3  <option value="2" selected="selected">test2</option>
4  <option value="3">test3</option>
5</select>
6
7var e = document.getElementById("ddlViewBy");
8var strUser = e.value;
9//Would make strUser be 2.
10
11var e = document.getElementById("ddlViewBy");
12var strUser = e.options[e.selectedIndex].text;
13//Would make strUser be test2.
Gianluca
03 Feb 2020
1var e = document.getElementById("ddlViewBy");
2var strUser = e.value;
3
Valeria
20 Sep 2018
1// reference to 'scripts' select list 
2// used throughout the examples below
3var sel = document.getElementById('scripts');
4
5// display value property of select list (from selected option)
6console.log( sel.value );
7
similar questions
queries leading to this page
get value select javascript