Get Select Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Select


The Select object represents an HTML <select> element.

You can access a <select> element by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<select id="mySelect" size="4">
</select>//from www  . j a v  a 2s .c o  m

<button onclick="myFunction()">get the number of option elements found in a drop-down list</button>

<p id="demo"></p>

function myFunction() {
    var x = document.getElementById("mySelect").length;
    document.getElementById("demo").innerHTML = x;


Related Tutorials