In this tutorial, we are going to teach you how you can count the number of words in textarea as user type in it. The first thing you need to do is to attach an onkeyup listener to your textarea tag. This function will be called whenever the user pressed the key. Specifically, when the user’s finger is moving upwards after pressing the key, then this event is called. In this function, we are passing a parameter this means the current node, which is textarea tag.

We will be using a regular expression to calculate the number of words separated by spaces.

#javascript #programming

Count words as user type - Textarea and JavaScript
1.55 GEEK