Input Button form Property - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Button


The form property returns the form object containing the input button.

This property is read only.

Return Value

A reference to the form element containing the input button. If the input button is not in a form, it returns null.

The following code shows how to return the id of the form containing the <input type="button"> element:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>

<form id="myForm">
<input type="button" onclick="myFunction()" id="myBtn" value="return the id of the form it belongs to">
</form>/*from   w  w w  .  j a  v a2s  .  co  m*/

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

function myFunction() {
    var x = document.getElementById("myBtn");
    document.getElementById("demo").innerHTML = x;


Related Tutorials