Javascript Form How to - Access the Form object that contains the RadioButton








Question

We would like to know how to access the Form object that contains the RadioButton.

Answer


<!-- w ww .j av  a 2s .c  o m-->
<html>
<body>
    <form name="form1">
    <input type="radio" name=button1>Box 1
    <br>
    <input type="radio" name=button2>Box 2
    <br><br>
    <input type="button" value="Get Form Name"
      onClick='console.log("The form name is: " + document.form1.button1.form.name)'>
    </form>
</body>
</html>

The code above is rendered as follows: