Javascript Form How to - Transfer focus away from checkbox








Question

We would like to know how to transfer focus away from checkbox.

Answer


<!--from w  ww.ja  va2 s  .  c om-->
<html>
    <script language="JavaScript">
    function removeFocus()
    {
      document.myForm.checkBox2.blur();
    }
    </script>
    <form name="myForm">
      I hold my focus after a click
      <input type="checkbox" name="checkBox1"><br>
      I cannot hold my focus after a click
      <input type="checkbox" name="checkBox2" onClick="removeFocus()">
    </form>
</html>

The code above is rendered as follows: