Radio formProperty
Radio Object
Definition and Usage
The form property returns a reference to the form containing the button.
If successful, this property returns a form object.
Syntax
radioObject.form
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the form property
Example
Example
The following example returns the id of the form to which the radio button belongs:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("red").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
Which color do you prefer?<br>
<input type="radio" name="colors" id="red">Red<br>
<input type="radio" name="colors" id="blue">Blue<br>
<input type="radio" name="colors" id="green">Green
</form>
<button type="button" onclick="displayResult()">Show the ID of the form it belongs to</button>
</body>
</html>
<html>
<head>
<meta charset="utf-8">
<title>Rookie Tutorial (example.com)</title>
<script>
function displayResult(){
var x=document.getElementById("red").form.id;
alert(x);
}
</script>
</head>
<body>
<form id="form1">
Which color do you prefer?<br>
<input type="radio" name="colors" id="red">Red<br>
<input type="radio" name="colors" id="blue">Blue<br>
<input type="radio" name="colors" id="green">Green
</form>
<button type="button" onclick="displayResult()">Show the ID of the form it belongs to</button>
</body>
</html>
Try it Yourself »
Radio Object Other Extensions