Input Button formProperty
Button Object
Definition and Usage
The form property returns a reference to the form that contains the button.
If the button is included, it returns a form object; if the button is not included, it returns null.
Syntax
buttonObject.form
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the form property
Example
Example
The following example returns the id of the form containing the button:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("button1").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
<input type="button" onclick="displayResult()" value="Display the form id containing the button" id="button1">
</form>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("button1").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
<input type="button" onclick="displayResult()" value="Display the form id containing the button" id="button1">
</form>
</body>
</html>
Try it Yourself »
Button Object Other Extensions