Javascript DOM HTML Input Search Object get

Introduction

The Input Search object represents an HTML <input> element with type="search".

We can access an <input> element with type="search" via document.getElementById():

var x = document.getElementById("mySearch");

Click the button to get the placeholder text of the search field.

View in separate window

<!DOCTYPE html>
<html>
<body>
<input type="search" id="mySearch" placeholder="Search for something..">
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {/*w w w .j  a v a  2s.  c o  m*/
  var x = document.getElementById("mySearch").placeholder;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>



PreviousNext

Related