Have an idea?

Visit Sawtooth Software Feedback to share your ideas on how we can improve our products.

Word counter feature included on Open-Ended questions

Is it possible to include a "Word Counter" feature on an Open-Ended question?

As an extension to this, restrict the respondent from entering above the specified number of maximum words, or force the respondent to enter within a range.

Thanks.
asked Jul 10 by Paul Moon Platinum (74,405 points)

1 Answer

0 votes
It can be done, but it's not as arbitrary as a character count as the definition of what defines a "word" has some room for ambiguity.  Try this:

<span class="[% QuestionName() %]_wordcount"></span>

<script>
$(document).ready(function(){
    updateWordCount('[% QuestionName() %]');
})

$(document).on('keyup', '#[% QuestionName() %]', function(){
    updateWordCount('[% QuestionName() %]');
})

function updateWordCount(questionName) {
    var matches = SSI_GetValue(questionName).match(/\S+/g);
    var count = matches ? matches.length : 0;
    $('.' + questionName + '_wordcount').text(count);
}
</script>
answered Jul 10 by Zachary Platinum Sawtooth Software, Inc. (121,625 points)
Thanks Zachary. Much appreciated.

I'll test your version out and report back to this post.

I just thought this would be a useful feature to many Sawtooth Software users as a standard feature under the Settings tab.

Stay tuned.
...