Question: How does Stackoverflow do the character counter saying xyz characters left?

![enter image description here](https://i.stack.imgur.com/fZD01.png)

Answer: 
HTML:

```
<textarea id="text" onkeyup="charCount(this);"></textarea>
<span id="chars"></span>

```

JS:

```
var maxChars = 500;
function charCount(el) {
   document.getElementById('chars').innerText = maxChars - this.value.length;
}

```

not tested, but that's the basics.
Probably something like this:

var max = 1000;

```
document.getElementById('freddy').onkeypress =
document.getElementById('freddy').onkeyup = 
document.getElementById('freddy').onkeydown = function(){
    var count = this.value.length;
    if(max < count){
        this.value = this.value.substring(0,999);
        return false;
    }
    setTimeout(function(){
        document.getElementById('susan').innerHTML =
          (max-count)+' characters left!';
    },1);
};

```

<http://jsfiddle.net/Paulpro/S4Dtu/>