Ron
Ron

Reputation: 51

How to print text to a textarea?

I have this code :

<script type="text/javascript">
    function GetChar(event) {
        var chCode = ('charCode' in event) ? event.charCode : event.keyCode;
        if (chCode == 13) {
            var textBox = document.getElementById('TEXTBOX');
            alert("The text in the box is: " + textBox.value);
            document.getElementById('test').innerHTML = ("The text in the box is: " + textBox.value);
            if (textBox.value == 'ninja') document.getElementById('teraminal').innerHTML = ("working!")
        }
    }
</script>

HTML:

<input type="text" id="TEXTBOX" size="40" value="" onKeyPress="GetChar (event);" />
<label id="test"></label>
<textarea rows="40" cols="80" readonly id="terminal" draggable="false" style="resize:none">

I want it to say "working" in the <textarea> when I type "ninja", but it's not working. Any ideas on how to fix it?

Upvotes: 2

Views: 96

Answers (1)

Quentin
Quentin

Reputation: 943470

Set the value property, not the innerHTML property and spell terminal consistently.

Upvotes: 3

Related Questions