I am looking for a way to display (in real-time) the number of characters in a text entry box | XM Community
Skip to main content

I am looking for a script that is similar to what is shown below for word count, but for character count instead. My JavaScript abilities are extremely limited and I have been unable to successfully adapt this script for character count.
The goal is to be able to display the characters within a text entry box to the survey respondent.
I am also interested in knowing if there is a way to modify the character count so that it includes (or excludes) spaces.
Thank you for any advice/assistance.
Here is the word count script I have previously used:
Qualtrics.SurveyEngine.addOnload(function() {
var q = jQuery("#"+this.questionId);
var input = q.find(".InputText");
input.after("

Word count: 0
");
var display = q.find(".wordCount");
countWords(input.get(0));
input.on("input", function() { countWords(this) });
input.blur(function() { this.value = this.value.trim(); });

function countWords(el) {
if(el.value.length > 0) display.text(el.value.match(/\\S+/g).length);
else display.text("0");
}
});
The above code is from this link.

Change:

  • el.value.match(/\\S+/g).length
    to
    el.value.length 

  • "Word count:" to "Character count:"

fyi...I wrote the code above


Awesome, thank you so much Tom!
Yes I saw that was your post. Thanks for that - both of these are extremely useful.


further to the above does anyone know how to add a gauge or a meter that would turn from red through amber to green the more respondent types?


Leave a Reply