I am currently utilizing Bootstrap
and the CKEditor5 Classic
.
I am looking to implement a character counter using ONKEYUP
in my textarea
that displays each time a key is released within div id countThis
.
I specifically require a solution using pure JavaScript, as I have attempted the following without success.
How can I successfully achieve this? Thank you for your help!
(Please note that jQuery should not be used!)
CODE
<div class="row">
<div class="form-group col-10">
<label class="form-label" for="txt">Description</label>
<textarea id="txt" class="form-control" onkeyup="CheckInput()"></textarea>
</div>
<div class="col-2 mt-4" id="countThis"></div>
</div>
ClassicEditor
.create(document.querySelector('#txt'))
.catch(error => {
console.error(error);
});
function CheckInput() {
var value = document.getElementById("txt").value.length;
console.log(value); // NO OUTPUT HERE
document.getElementById("countThis").innerHTML = value;
}