Javascript Form How to - Get RadioButton name








Question

We would like to know how to get RadioButton name.

Answer


<html>
<body>
    <form name="form1">
        <input type="radio" name=myButton>Box 1
        <br><br>
        <input type="button" value="Get Name" onClick='console.log("The name of the button is: " +
                document.form1.myButton.name)'>
    </form>
</body><!-- ww  w .j  a v a 2 s.co  m-->
</html>

The code above is rendered as follows: