Javascript Form How to - Handle on Select/highlight event








Question

We would like to know how to handle on Select/highlight event.

Answer


<html>
    <head>
    <script language="JavaScript">
    function setText(){<!-- w w w .  jav a 2s.  co  m-->
      document.myForm.myText2.value = document.myForm.myText1.defaultValue;
    }
    </script>
    </head>
    <body>
    <form name="myForm">
      <input type=TEXT value="Highlight Me?" name="myText1" onSelect='setText()'>
      <br>
      <input type=TEXT value="" name="myText2">
    </form>
    </body>
</html>

The code above is rendered as follows: