javascript - Write how manu characters left in textbox -
i have textbox max value of 10, , want #pid p tag write 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() { (var = 10; >= 1; i--) { contentcount = 10; pid.innerhtml = parseint(contentcount - 1); } } content.onkeypress = charsleft;
all managed when start typing, see 9, keep typing stays 9.
i want pure js, no libraries.
function charsleft() { pid.innerhtml = content.value.length > 0 ? content.getattribute("maxlength") - content.value.length + " chars left" : "max 10 chars"; } content.onkeyup = charsleft;
see demo.
Comments
Post a Comment