Javascript DOM HTML Input Search value Property get

Introduction

Get the text of a search field:

var x = document.getElementById("mySeach").value;

Click the button to display the value attribute of the search field.

View in separate window

<!DOCTYPE html>
<html>
<body>

Search: <input type="search" id="mySearch" value="Food">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*  w w w.ja va 2 s. c  om*/
  var x = document.getElementById("mySearch").value;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related