JavaScript Count Words - Counter Code
number of words
enter text, please
(less than 5 words)
JavaScript Count Words - Counter Code
The JavaScript word counter is a great utility if your web site uses forms and textfields. Not only does it count the words entered by your visitors. It also prevents your visitors from writing too long of text. If the text is too long it will be cut by the script. Very easy configuration of the maximum text length. In this sample the maximum text length is restricted to 5 words. Cross-browser. Try to write a longer text in order to see the effect.

Configuration:

Step 1 Paste the following code into your web page:


Step 2: Open your web page, go to the top of script and configure the maximum number of words that may be entered into the text field (red number below):

// What's the maximum length of your textfield (number of words)
var maximalwords=5


Download 500 free copy-and-paste scripts