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.

fiddle

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

Popular posts from this blog

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -