You can also use simple javascript event handling to display the number of characters for input elements. No server-side processing required.
This javascript catches the keystroke event for the "txt" text area and shows the number of characters in the "count" space.
See how it works
http://aaron.oirt.rutgers.edu/myapp/root/charCount.html
<html>
<head>
<script>
function go() {
var txt=document.getElementById("txt");
txt.onkeydown = countTxt;
}
function countTxt() {
var txt=document.getElementById("txt");
var count=document.getElementById("count");
count.innerHTML = txt.value.length+1;
}
</script>
</head>
<body onload="go()">
<h3>type in the text area and see the count change</h3>
<textarea id="txt" rows="8" cols="30"></textarea>
<br>
count: <span id="count"> 0</span>
</body>
The account can be disconnected from my + -1 - correction, which (if you really want it) is left to the reader.
source
share