Search code examples
javascriptdom-eventstextareaonkeyup

onkeyup event in textarea


I have a very basic input/output structure in HTML:

<textarea id="input" onkeyup="sendCode()">
Hello World!
</textarea> 

<div id="output"></div>

And I have JS function that should pass everything from input to output:

var input = document.getElementById("input");
var output = document.getElementById("output");

function sendCode(){
 output.innerHTML = input.innerHTML;
}

The sendCode() function works when I call it manually, but it seems that onkeyup event not firing in this textarea.

Here is jsfiddle: http://jsfiddle.net/mudroljub/y5a2n8ab/

Any help?

UPDATE: jsfiddle is updated and working now.


Solution

  • Use value since it's not a content text but a value property

    var input = document.getElementById("input");
    var output = document.getElementById("output");
    
    function sendCode(){
     output.innerHTML = input.value;
    }
    

    And a working demo here