Javascript Form How to - Removes focus from input text box








Question

We would like to know how to removes focus from input text box.

Answer


<!--  w w  w  .  ja v a2s.  com-->

<html>
<head>
    <script language="JavaScript">
    function removeFocus(){
      document.myForm.myText.blur();
    }
    </script>
</head>
<body>
    <P>
    <form name="myForm">
      <input type=TEXT value="hello world" name="myText">
      <input type=BUTTON value="Click to Remove Focus" name="myButton"
             onClick="removeFocus()">
    </form>
</body>
</html>

The code above is rendered as follows: