Javascript Reference - HTML DOM Input Text form Property








The read only form property returns a reference to the form that contains the text field.

Browser Support

form Yes Yes Yes Yes Yes

Syntax

var v = textObject.form 

Return Value

A reference to the form element containing the text field. If the text 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="text"> element.


<!DOCTYPE html>
<html>
<body>
<!--   w  w  w. j a  va2 s.  c om-->
<form id="myForm">
  Name: <input type="text" id="myText" value="abc">
</form>
<button onclick="myFunction()">test</button>

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

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

</body>
</html

The code above is rendered as follows: