pankaj
12/28/2016 - 8:23 AM

Count characters and limit the max

Count characters and limit the max

<textarea onkeyup="countChar(this, 200)" maxlength="200"></textarea>
<div id="charNum200"></div>

<script>
function countChar(val, max)
{
    var len = $(val).val().length;
    if (len >= max) {
        $('#charNum'+max).text('You have reached the limit');
    } else {
        var char = max - len;
        $('#charNum'+max).text(char + ' characters left');
    }
}
</script>