Bootstrap FreeKB - JavaScript - How to count characters entered into a textarea using JavaScript
JavaScript - How to count characters entered into a textarea using JavaScript

Updated:   |  JavaScript articles

Added the following script to the HEAD of your markup.

<script src="http://code.jquery.com/jquery-1.5.js"></script>
<script>
function CountCharacters(val) {
  var len = val.value.length;
  if (len >= 50) {val.value = val.value.substring(0, 50); }
  else {$('#charNum').text(50 - len); }
};
</script>

 

Then, add onkeyup="CountCharacters(this)" to the textarea.

<textarea onkeyup="CountCharacters(this)"></textarea>

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter 1fe91a in the box below so that we can be sure you are a human.