Javascript Reference - HTML DOM Input Button form Property








The read only form property returns a reference to the form containing the input button.

Browser Support

form Yes Yes Yes Yes Yes

Syntax

var v = buttonObject.form 

Return Value

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


<!DOCTYPE html>
<html>
<body>
<form id="myForm">
<input type="button" onclick="myFunction()" id="myBtn" value="test">
</form><!--from   www .j a v a 2 s .c  o m-->
<p id="demo"></p>
<script>
function myFunction() {
    var x = document.getElementById("myBtn").form.id;
    document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The code above is rendered as follows: