Edit This Code:
<!DOCTYPE html>
<html>
<body>

<h3>A demonstration of how to access a DATALIST element</h3>

<form>
  <input list="myDatalist">
  <datalist id="myDatalist">
    <option value="Internet Explorer">
    <option value="Firefox">
    <option value="Chrome">
    <option value="Opera">
    <option value="Safari">
  </datalist>
</form>

<p>Click the button to get the number of option elements in the datalist.</p>

<button onclick="myFunction()">Try it</button>

<p><strong>Note:</strong> The input element's list attribute is used to bind it together with the datalist element.</p>

<p><strong>Note:</strong> The datalist element is not supported in Internet Explorer 9 and earlier versions, or in Safari.</p>

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

<script>
function myFunction() {
    var x = document.getElementById("myDatalist").options.length;
    document.getElementById("demo").innerHTML = "Found " + x + " options in the list.";
}
</script>

</body>
</html>


Result:
Try it Yourself - © w3schools.com
Privacy Policy