Javascript Reference - HTML DOM Input Number form Property








The form property gets the form containing the number field.

Browser Support

form Yes Yes Yes Yes Yes

Syntax

var v = numberObject.form

Return Value

A reference to the form element containing the number field. If the number field is not in a form, null is returned.





Example

The following code shows how to get the id of the form containing the <input type="number"> element.


<!DOCTYPE html>
<html>
<body>
<!--  w  ww  . j a  v a2s.  co  m-->
<form id="myForm">
  <input type="number" id="myNumber" value="2">
</form>
<button onclick="myFunction()">test</button>
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myNumber").form.id;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: