How to count the characters on a text entry question and record the numeric value as embedded data | XM Community
Skip to main content
Question

How to count the characters on a text entry question and record the numeric value as embedded data

  • May 17, 2021
  • 4 replies
  • 332 views

Forum|alt.badge.img+4

Hi all,
I have a text entry question and want to count the number of characters the response has and record this numeric value as an embedded data. This should not be visible for the respondents. I want to use the embedded data later on to trigger actions. Does anybody knows how to do it and what the java logic would be?
Thanks

4 replies

Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • May 17, 2021

Qualtrics.SurveyEngine.addOnReady(function () {
    let text_entered = this.questionContainer.querySelector(".InputText");
    text_entered.oninput = function () {
        Qualtrics.SurveyEngine.setEmbeddedData("text_length", text_entered.value.length);
    };
});


Forum|alt.badge.img+4
  • Author
  • Level 1 ●
  • May 17, 2021

Thanks Ahmed!
So, i should paste this code in the text entry question and text_lenght would be the embedded data, right?


Forum|alt.badge.img+22
  • Level 7 ●●●●●●●
  • May 17, 2021

In the javascript of a text entry question.


Forum|alt.badge.img+4
  • Author
  • Level 1 ●
  • May 17, 2021

Thanks ahmedA,
It works perfect! you are a guru!