Javascript DOM HTML Input Search form Property get

Introduction

Return the id of the form containing the <input type="search"> element:

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

Click the button to display the id of the form the search field belongs to.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm">
  <input type="search" id="mySearch">
</form>//  ww  w.j  a  v a2  s.c om
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("mySearch").form.id;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The form property returns a reference to the form containing the search field.

This property returns a form object on success.

This property is read only.

If the search field is not in a form, null is returned




PreviousNext

Related