I am trying to implement a character counter to my `textarea` tag, but something definitely isn't working. I tried several approaches, but unsuccessfully. I know there are lots of implementation on web, but I couldn't find something that is working to my code. I am quite beginner in this field, and I simply can't get how this works. Code:
...............
<div id='id_text' class="control-group">
<label for="id_text" class="control-label">
Text
</label>
<div class="controls">
<label for="field"></label>
<textarea id="field" onkeydown="countChar(this)" maxlength="800"></textarea>
</div>
<span>Char Left:</span> <span id="charNum"> </span>
</div>
....................................
script:
<script src="http://code.jquery.com/jquery-1.5.js"></script>
<script>
function countChar(val) {
var len = val.value.length;
$('#charNum').text(800 - len);
}
</script>
NOTE: The script is positioned on the bottom of the HTML page (I tried to place it on top, but in vain). The script is simple: I just want to take the number of characters from the textarea and then to display the remaining characters to the user.
I looked for other answers here, I looked for answers on other websites, but I think there is a problem with my code and I don't get it.
NOTE2: The textarea is part of a <form>. And I am using django framework.
Thank you so much for your help and attention!
EDIT:
I have tried the code by Rory and this is what I see.

