views:

144

answers:

1

How do you manipulate text inside of a textarea as the user types in it?

+2  A: 

You'd use the onKeyUp event to detect key presses, then use the value property of the textarea to get and/or set the value.

<script language="text/javascript">
    function change_text() {
        // get the text
        text = document.getElementById("your_textarea").value;

        // ...

        // set the text
        document.getElementById("your_textarea").value = text;
    }
</script>

...

<textarea id="your_textarea" onKeyUp="change_text()"></textarea>
yjerem