Javascript DOM HTML Fieldset form Property get

Introduction

Return the id of the form containing the <fieldset> element:

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

Click the button to display the id of the form the fieldset belongs to.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm">
  <fieldset id="myFieldset">
  <legend>MyNameFieldset:</legend>
  Name: <input type="text"><br>
  Email: <input type="text"><br>
  Date of birth: <input type="text">
  </fieldset>
</form>// ww  w. j av  a 2  s  .com
<button onclick="myFunction()">Test</button>

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

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

</body>
</html>

The form property returns a reference to the form that contains the fieldset.

This property returns a form object on success.

This property is read only.

If the fieldset is not in a form, null is returned.




PreviousNext

Related