Javascript Form How to - Handle text Change event for TextArea








Question

We would like to know how to handle text Change event for TextArea.

Answer


<!-- w w w.j a  va 2s. c  o m-->
<html>
<head>
    <script language="JavaScript">
    function changeBack(){
      document.myForm.myTextArea.value = document.myForm.myTextArea.defaultValue;
    }
    </script>
</head>
<body>
    <form name="myForm">
      <textarea name="myTextArea" rows=2 cols=50 onChange='changeBack()'>
      Here is some text in my text area.
      </textarea>
    </form>
</body>
</html>

The code above is rendered as follows: