The read only form
property returns a reference to the form containing the input button.
form |
Yes | Yes | Yes | Yes | Yes |
var v = buttonObject.form
A reference to the form element containing the input button. If the input button is not in a form, null is returned.
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: