Select selectedIndex Property - selectedIndex property returns "-1" if no options are selected: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select

Description

Select selectedIndex Property - selectedIndex property returns "-1" if no options are selected:

Demo Code

ResultView the demo in separate window

<!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>

Related Tutorials