Datalist options Collection namedItem(name_or_id) - Get the value of the option with id="google" in a datalist: - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Datalist

Description

Datalist options Collection namedItem(name_or_id) - Get the value of the option with id="google" 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 id="google" value="C">
    <option value="D">
    <option value="E">
  </datalist>
</form>//from   w ww  .ja  va 2  s .c  o  m

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

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

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

</body>
</html>

Related Tutorials