Minimum Word Count | XM Community
Skip to main content
Hello, I have searched for the answer to this question in the Community and have contacted Qualtrics for support, but I can't seem to find an answer.



I am attempting to create a scholarship application for our Honors Program that includes an essay. The essay must be a minimum of 500 words.



So far, I have tried to use custom validation and JavaScript to show the number of words typed as well as validate that the user has input more than 500 words. They won't be able to submit the application unless this minimum word count is met.



Custom Validation



Matches RegEx: (\\b[A-Za-z0-9\\s'_-]+\\b){500,}



JavaScript

Qualtrics.SurveyEngine.addOnload(function()

{

/*Place your JavaScript here to run when the page loads*/



});



Qualtrics.SurveyEngine.addOnReady(function()

{

/*Place your JavaScript here to run when the page is fully displayed*/

var display = $('wordCountDisplay');

var questionID = this.questionId;

var textbox =$('QR~' + questionID);

var that = this;

function countWords(s){

s = s.replace(/\\n/g,' '); // newlines to space

s = s.replace(/(^\\s*)|(\\s*$)/gi,''); // remove spaces from start + end

s = s.replace(/[ ]{2,}/gi,' '); // 2 or more spaces to 1

if(s == ''){

return 0;

}else{

return s.split(' ').length;

}

}



textbox.onkeyup = function(e){

display.update(countWords(textbox.value));

console.log(textbox.value);



}

});



Qualtrics.SurveyEngine.addOnUnload(function()

{

/*Place your JavaScript here to run when the page is unloaded*/



});



Link to Survey: https://gardnerwebb.az1.qualtrics.com/jfe/form/SV_00OxwGxeou4gkex



Does anyone have a solution for this?



I suppose a workaround could be a file upload, but we had this functionality in Wufoo Forms, and I'd really like to recreate this for my survey manager in Qualtrics.



Thanks in advance for your guidance or suggestions.



Cindy
Refer below post:-

https://www.qualtrics.com/community/discussion/2337/limit-the-number-of-words-in-the-text-box#latest
@ctribucher,



Check the number of words returned by the countWords function. If it is less than 500 hide and/or disable the Next button. Show and/or enable the Next button if it is greater than or equal to 500.

TomG
I tried to hide and then conditionally show the Next button, but my syntax seems wrong. Any idea?
```
Qualtrics.SurveyEngine.addOnReady(function()
{
   /*Place your JavaScript here to run when the page is fully displayed*/
   this.hideNextButton();

   var questionID = this.questionId;
   var textbox =$('QR~' + questionID);

   function countWords(s) {
      s = s.replace(/\\n/g,' '); // newlines to space
      s = s.replace(/(^\\s)|(\\s$)/gi,''); // remove spaces from start + end
      s = s.replace(/n ]{2,}/gi,' '); // 2 or more spaces to 1
      if(s == ''){
         return 0;
      } else {
         return s.split(' ').length;
      }
   }

   textbox.onkeyup = function(e) {

      var aa = countWords(textbox.value);
      Qualtrics.SurveyEngine.setEmbeddedData("ED1", aa);
      }

   if (aa >= 14) {
      this.showNextButton();
   }
});
```


duc_pq ,

this.showNextButton();
is inside the onkeyup function, so 'this' no longer refers the to Qualtrics question object where the showNextButton() function resides.
At the beginning of the addOnReady function add
var qobj = this;
then use
qobj.showNextButton();
in the onkeyup function.


Leave a Reply