JSFiddle - React, Tailwind, and code Playground

by dandrade78

HTML

<textarea name="ta" id="ta" rows="4" cols="50" onkeypress="if (!isNaN(String.fromCharCode(window.event.keyCode))) return true; else return false;">
 ABC
 DEF
 GHI
 </textarea>
 <input type="text" id="rt" name="textnumber" value="" >

JavaScript

/* UPDATE from https://jsfiddle.net/dandrade78/vbrzhcw6/6/
https://stackoverflow.com/questions/59776321/realtime-counter-endlines-in-textarea

 Now not have error in start, but dont work...
 
 Error is after test function is Uncaught TypeError: Cannot set property 'value' of null at HTMLTextAreaElement.update */
    
window.onload=function(){

(function() {
    var tarea = document.querySelector('#ta')
    var input = document.querySelector('#rt')

    function update() {
      var res = (tarea.value.match(/\n/g)) ? tarea.value.match(/\n/g).length : 0;

      input.value = res;
    }

    tarea.addEventListener('input', update)
})(); 
}//window.onload