Javascript Form How to - Set focus to Reset button








Question

We would like to know how to set focus to Reset button.

Answer


<!--   w ww  . j  av  a2  s  .c  o m-->
<html>
<body>
    <script language="JavaScript">
    function focusReset(){
         document.form1.resetbutton.focus();
    }
    </script>
    <form name="form1">
        Enter Name: <input type="text" Name="name" Size=15>
        <br>
        Enter Phone: <input type="text" Name="phone" Size=10>
        <br><br>
        <input type="reset" name=resetbutton value=Reset>
        <br>
        <br>
        <input type="button" value="Set Focus to Reset" onClick='focusReset()'>
        <br>
    </form>
</body>
</html>

The code above is rendered as follows: