The read only form
property returns a reference to the form that contains the fieldset.
form |
Yes | Yes | Yes | Yes | Yes |
var v = fieldsetObject.form
A reference to the form element that contains the fieldset.
If the fieldset is not in a form, null is returned.
The following code shows how to get the id of the form containing the <fieldset> element.
<!DOCTYPE html>
<html>
<body>
<form id="myForm">
<fieldset id="myFieldset">
<legend>Information:</legend>
Name: <input type="text"><br>
Date of birth: <input type="text">
</fieldset>
</form><!--from ww w.j av a2s . com-->
<p id="demo"></p>
<button onclick="myFunction()">test</button>
<script>
function myFunction() {
var x = document.getElementById("myFieldset").form.id;
document.getElementById("demo").innerHTML = x;
}
</script>
</body>
</html>
The code above is rendered as follows: