JavaScript Characters Count Functions
JavaScript characters Counter script. onClick button count characters, textarea onInput (paste change keyup) count characters
0
document.getElementById("count-btn").onclick = function() {
var total_length = document.getElementById("user-text").value.length;
document.getElementById("char-length").innerText = total_length;
};
<textarea id="user-text" rows="10" cols="50"></textarea>
<button id="count-btn">count characters</button>
<div id="char-length"></div>
0
document.getElementById("user-text").onchange = function() {
var total_length = this.value.length;
document.getElementById("char-length").innerText = total_length;
};
0
document.getElementById("user-text").oninput = function() {
var total_length = this.value.length;
document.getElementById("char-length").innerText = total_length;
};
100
(function() {
let limit = 100;
let textaea = document.getElementById("user-text");
textaea.setAttribute("maxlength", limit);
textaea.oninput = function() {
textaea.setAttribute("maxlength", limit);
let total_length = this.value.length;
document.getElementById("char-length").innerText = limit - total_length;
};
})();