Javascript Form How to - Handle focus got event for Reset Button








Question

We would like to know how to handle focus got event for Reset Button.

Answer


<!--  w  ww  .j  a v  a  2 s  .  c o m-->
<html>
<body>
    <script language="JavaScript">
    function setMsg(){
         console.log("Focus is set on the reset button.");
    }
    </script>
    <form name="form1">
        Click the reset button.
        <br><br>
        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 onFocus='setMsg()'>
        <br>
    </form>
</body>
</html>

The code above is rendered as follows: