Community Groups are officially here!
We've released Groups, a new feature that enables us to connect community members of similar industries and interests in a shared, private space. You can check out all of the details here, including information about who can join, how to join, and what Groups are currently offered. Please leave your feedback through this Community Groups Feedback Survey.

How do I show the number of words in text entry boxes? I have several on the page.

Dax
Dax Provo, UTFounding Community Member CEP (Chief Executive Paw-ficer)

How do I show the number of words in text entry boxes? I have several on the page.

Best Answer

Answers

  • JulieT
    JulieT WisconsinCommunity Member, Qualtrics Brand Admin Sage ✭✭✭
    edited November 2017
    1. Select your Text Entry question.
    2. Click on Custom Validation in the right panel.
    3. In the 2nd box, select your question text as the text to analyze.
    4. Pull down the 3rd box and change it from "Equal to" to "Matches Regex"
    5. Paste ^\s(\S+\s+){0,249}\S$ in the last text box. Change the upper number to the limit you choose.
  • AnthonyR
    AnthonyR Tucson AzFounding Community Member, Community Member Superuser ✭✭✭✭

    @JulieT said:
    1. Select your Text Entry question.
    2. Click on Custom Validation in the right panel.
    3. In the 2nd box, select your question text as the text to analyze.
    4. Pull down the 3rd box and change it from "Equal to" to "Matches Regex"
    5. Paste ^\s(\S+\s+){0,249}\S$ in the last text box. Change the upper number to the limit you choose.

    This will let you limit the number of words, but it doesn't display the number of words while typing, which is what I think the question is. I'll try and work out the JS for this later today.

  • Akdashboard
    Akdashboard South CarolinaCommunity Member Superuser ✭✭✭✭

    @JulieT said:
    1. Select your Text Entry question.
    2. Click on Custom Validation in the right panel.
    3. In the 2nd box, select your question text as the text to analyze.
    4. Pull down the 3rd box and change it from "Equal to" to "Matches Regex"
    5. Paste ^\s(\S+\s+){0,249}\S$ in the last text box. Change the upper number to the limit you choose.

    Has anyone gotten this to work? I can't get the custom validation to work with this logic.

  • ctribucher
    ctribucher North CarolinaCommunity Member Qubie ✭

    I'm struggling with this is well. When I posed this question to Qualtrics Customer Support, they directed me to use embedded data.

    Here's what I was told:

    "Unfortunately Regex expressions and java script are outside of scope of support, and I cannot help you with them, but you can do something different, rather than using a Regex expression, you can create an embedded data and assign the word count in each keyboard event (in the same way that currently you are updating the count), then in the custom validation you can create the logic to pass the validation if embedded data text_length is greater than or equal to 500, it is important to create the embedded data before the block where you are using the java script, in your case you only have one element so the embedded data must be at the very top of the survey flow."

    None of this made any sense to me and I sure would appreciate the help!

  • TomG
    TomG Raleigh, NCCommunity Member, Qualtrics Brand Admin Wizard ✭✭✭✭✭

    @ctribucher said:
    I'm struggling with this is well. When I posed this question to Qualtrics Customer Support, they directed me to use embedded data.

    Here's what I was told:

    "Unfortunately Regex expressions and java script are outside of scope of support, and I cannot help you with them, but you can do something different, rather than using a Regex expression, you can create an embedded data and assign the word count in each keyboard event (in the same way that currently you are updating the count), then in the custom validation you can create the logic to pass the validation if embedded data text_length is greater than or equal to 500, it is important to create the embedded data before the block where you are using the java script, in your case you only have one element so the embedded data must be at the very top of the survey flow."

    None of this made any sense to me and I sure would appreciate the help!

    It's not you. It doesn't make any sense because embedded data fields don't get updated until you submit the page. So, checking an embedded data field that won't be updated with the applicable data until after you leave the page will never work.

    You should start a new thread with your specific question.

  • ctribucher
    ctribucher North CarolinaCommunity Member Qubie ✭

    Thanks, @TomG! I feel like this should be easier than it is turning out to be. Will start a new thread.

  • LukeP
    LukeP Community Member Qubie ✭

    AnthonyR or anyone else, could you please advise on how to apply this to:


    1/ a text entry box that is added to a row statement

    2/ a side-by-side text entry column


    Any advise would be greatly appreciated!

  • LH_Qual_User
    LH_Qual_User New YorkCommunity Member, Qualtrics Brand Admin Qubie ✭

    This is helpful. I am wondering what is the code to reference a different question text. I would like it to show the character limit under the text entry box as opposed to above it. So, how would the Javascript read to count the words in the text questionID from the previous question. Or maybe there is another alternative way to do this.


  • TedyA
    TedyA RotterdamCommunity Member Qubie ✭

    I was looking for alternate codes to the one mentioned in this thread, as I need multiple word counts for multiple text entries within the same block. Saw another piece of code that adds a word count under the box of text entry. You also don't need to add anything to the HTML section of the description.

    Qualtrics.SurveyEngine.addOnload(function() {
         var q = jQuery("#"+this.questionId);
         var input = q.find(".InputText");
         input.after("<div style='font-size:0.8em;float:right'>Word count: <span class='wordCount'>0</span></div>");
         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");
         }
    });
    

    It's a little late, but perhaps you or some others may still have some use for it.


  • TomG
    TomG Raleigh, NCCommunity Member, Qualtrics Brand Admin Wizard ✭✭✭✭✭