Javascript Form How to - Remove the focus from a button








Question

We would like to know how to remove the focus from a button.

Answer


<html>
    <head>
        <script language="JavaScript">
    function removeFocus()<!--   www  . j a v a  2 s .c  o  m-->
    {
      document.myForm.button2.blur();
    }
    </script>
    </head>
    <body>
    <form name="myForm">
      <input type="button"
             value="I hold my focus after a click"
             name="button1"><br>
      <input type="button"
             value="I can not hold my focus after a click"
             name="button2"
             onClick="removeFocus()">
    </form>
    </body>
</html>

The code above is rendered as follows: