Javascript DOM HTML Output form Property

Introduction

Get the id of the form containing the <output> element:

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

Click the button to display the id of the form the output element belongs to.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm" oninput="x.value=parseInt(a.value)+parseInt(b.value)">0
  <input type="range" id="a" value="50">100
  +<input type="number" id="b" value="50">
  =<output id="myOutput" name="x" for="a b"></output>
</form>/*  w  w  w. j  a va 2  s.  c om*/

<button type="button" onclick="myFunction()">Test</button>

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

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

</body>
</html>

The form property returns a reference to the form containing the <output> element.

This property returns a form object on success.

This property is read only.

If the <output> element is not in a form, null is returned




PreviousNext

Related