Javascript examples for DOM HTML Element:Select
Select selectedIndex Property - selectedIndex property returns "-1" if no options are selected:
<!DOCTYPE html> <html> <body> <select id="mySelect" size="4"> <option>CSS</option> <option>Javascript</option> <option>Database</option> <option>SQL</option> </select>//from w w w . j a v a 2 s .c om <button type="button" onclick="myFunction()">Display index</button> <script> function myFunction() { var x = document.getElementById("mySelect").selectedIndex; console.log(x); } </script> </body> </html>