Datalist options Collection [index] - Get the value of the first option (index 0) in a datalist: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Datalist

Description

Datalist options Collection [index] - Get the value of the first option (index 0) in a datalist:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<form>
  <input list="browsers" name="browser">
  <datalist id="browsers">
    <option value="A">
    <option value="B">
    <option value="C">
    <option value="D">
    <option value="E">
  </datalist>
</form>/*from  w ww.  j  a  v a 2 s  .c om*/

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

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

<script>
function myFunction() {
    var x = document.getElementById("browsers").options[0].value;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

Related Tutorials