Javascript Form How to - Apply focus to the button without invoking the button's onFocus event handler








Question

We would like to know how to apply focus to the button without invoking the button's onFocus event handler.

Answer


<html>
    <script language="JavaScript">
    function moveFocus()<!--   www.  j  a  va2  s .  c om-->
    {
      document.myForm.button1.focus();
    }
    </script>
    <form name="myForm">
      <input type="button"
             value="I hold my focus after a click"
             name="button1"><br>
      <input type="button"
             value="I shift my focus when click"
             name="button2"
             onClick="moveFocus()">
    </form>    
</html>

The code above is rendered as follows: