Javascript Form How to - Set the focus to the radio button








Question

We would like to know how to set the focus to the radio button.

Answer


<!-- w w w  . j  ava 2  s  .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="Set Focus to Box 1" onClick='document.form1.button1.focus()'>
    </form>
</body>
</html>

The code above is rendered as follows: