Get Input Search Field - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Search

Introduction

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

You can access an <input> element with type="search" by using getElementById():

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="search" id="mySearch" placeholder="Search for something..">

<button onclick="myFunction()">get the placeholder text of the search field</button>

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

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

</body>
</html>

Related Tutorials