I have a textbox with a max value of 10, and I want #pid p tag to write the number of remaining characters.
html:
<textarea id="content" maxlength="10"></textarea>
<p id="pid">max 10 chars</p>
javascript:
var content = document.getElementById('content');
var pid = document.getElementById('pid');
function charsLeft() {
for (var i = 10; i >= 1; i--) {
contentCount = 10;
pid.innerHTML = parseInt(contentCount - 1);
}
}
content.onkeypress = charsLeft;
All i managed to do is that when I start typing, i see 9, but as I keep typing it stays as 9.
I want to do this with pure JS, no libraries.