Javascript DOM HTML Select type Property get

Introduction

Return which type of form element a drop-down list is:

var x = document.getElementById("mySelect").type;

Click the button to return which type of form element the dropdown list is.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form>
  <select id="mySelect">
    <option>Apple</option>
    <option>Pear</option>
    <option>Banana</option>
    <option>Orange</option>
  </select>
</form>// w  w w . j  a  va2  s .  c  o m
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("mySelect").type;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The type property returns which type of form element a drop-down list is.

For a drop-down list this will be "select-one" or "select-multiple".

Return which type of form element a drop-down list that allows multiple selections is:

var x = document.getElementById("mySelect").type;

Click the button to return which type of form element the dropdown list is.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form>
  <select id="mySelect" multiple>
    <option>Apple</option>
    <option>Pear</option>
    <option>Banana</option>
    <option>Orange</option>
  </select>
</form>//from w  w  w .  j ava 2s.co m

<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("mySelect").type;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related