Javascript DOM HTML Input Hidden form Property get

Introduction

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

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

Click the button to display the id of the form the hidden input element belongs to.

View in separate window

<!DOCTYPE html>
<html>
<body>
<form id="myForm">
  <input type="hidden" id="myInput">
</form>//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("myInput").form.id;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The form property returns a reference to the form containing the hidden input field.

This property returns a form object on success.

This property is read only.

If the hidden input field is not in a form, null is returned




PreviousNext

Related