If you need to limit the number of words that a user can input into a Long Text type question, and you'd like to include a word counter, this will let you accomplish this:
1. Put this HTML in your question Help field:
<div class="word-counter">Word Count: <label id="count-label513">0</label>/200</div>
a) Find the questionID for your text question:
b) Below, replace label513 with label
YourQuestionID -- this allows you to support more than one text area per page
2. Under Advanced settings, look for the heading "Script->Javascript for this question" and add:
var limitWord = 200;
$("#answer268778X29X513").keyup(function () {
$this = $(this);
var regex = /\s+/gi;
var wordcount = jQuery.trim($this.val()).replace(regex, ' ').split(' ').length;
if (wordcount <= limitWord) {
chars = $this.val().length;
} else {
var text = $(this).val();
var new_text = text.substr(0, chars);
$(this).val(new_text);
wordcount --;
}
$("#count-label513").html(wordcount);
});
In the above script:
a) Replace limitWord = 200 to your own word limit value
b) Replace answer268778X29X513 with the question ID (use your browser's Element Inspector to find this). Here's an animation of how to do this:
c) Replace label513 with the value you used in Step #1
3. Under General Options for your question, in the Validation field, enter this reg-ex:
/^[-\w]+(?:\W+[-\w]+){0,200}\W*$/
Change 200 to your max number of words
4. Save and then preview and test your question: