Javascript DOM HTML Input Radio form Property

Introduction

Get the id of the form containing the <input type="radio"> element:

var x = document.getElementById("myCheck").form.id;

Click the button to display the id of the form the radio button belongs to.

View in separate window

<!DOCTYPE html>
<html>
<body>

<form id="myForm">
Radio Button:<input type="radio" id="myRadio">
</form>/* w ww . j  av a 2 s  .  co m*/
<button onclick="myFunction()">Test</button>

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

<script>
function myFunction() {
  var x = document.getElementById("myRadio").form.id;
  document.getElementById("demo").innerHTML = x;
}
</script>

</body>
</html>

The form property returns a reference to the form that contains the radio button.

This property returns a form object on success.

This property is read only.

If the checkbox is not in a form, null is returned




PreviousNext

Related