I have this code:
function contar() {
var num_caracteres;
num_caracteres = document.form1.txtTexto.value.length;
document.getElementById("contador").innerHTML = num_caracteres;
setTimeout("contar()", 100);
}
<body>
<form id="form2" name="form1" method="post" action="">
<label>
<input type="text" name="txtTexto" id="txtTexto" onkeypress="contar()"/>
</label>
<p><label id="contador"></label></p>
</form>
</body>