Is it possible to parse through a list of strings in a textbox answer? | XM Community
Solved

Is it possible to parse through a list of strings in a textbox answer?

  • 3 December 2018
  • 3 replies
  • 47 views

Can qualtrics find ALL strings within a predefined list in a textbook answer? My understanding is that the "contains" function will stop searching once it finds the first string within the predefined list. However, I was wondering if it is possible for the platform to search for all elements within a list, instead of stopping at the first one.

I am trying to build a question in my survey that 1) will only be displayed if certain keywords are contained within a prior textbox response, and 2) will include one of these selected keywords piped-into the text of the question. The main concern is that I do not want the survey to always pipe-in the same keyword across all participants. As a result, I want to understand if it is possible to use qualtrics to parse through and find all relevant strings in a textbox, pending on whether any of the selected strings are present it would display the next question, and it would randomly select one string from this predefined list to pipe it into the next question.

E.g., The first question would ask participants to describe what type of pet they own. The second question would only display if the participant included the words 'dog', 'cat' or 'mouse' in the textbook answer. This second question would ask: Please tell us more about your 'dog'. If all 3 keywords are present in the first answer, the word 'dog' should not always be displayed in the next question - ideally there would be a random selection between these 3 keywords, so that different participants are exposed to different prompts.

It would be great to know if it is possible to build-in this functionality into a qualtrics survey or if I should be looking for a different platform.

Thank you!
icon

Best answer by TomG 4 December 2018, 01:15

View original

3 replies

Userlevel 7
Badge +27
Yes, it is possible to do this in a Qualtrics survey using JavaScript.
Thank you Tom this is very helpful. I have two follow-up questions:

Can you confirm whether it is possible to use JavaScript to pipe-in only select keywords (strings) from a larger textbox response? In the example above, would it be possible to extract only the keywords 'dog', 'cat' or 'mouse' from a larger textbox response and pipe-in only these selected keywords into the next question?

Finally, where would you add this JavaScript code when building the survey? Would it be through the "Add JavaScript" function or would I need to access the back-end of the survey to change this?

Thank you again for your help!
Userlevel 7
Badge +27
> @EGuzman said:
> Can you confirm whether it is possible to use JavaScript to pipe-in only select keywords (strings) from a larger textbox response? In the example above, would it be possible to extract only the keywords 'dog', 'cat' or 'mouse' from a larger textbox response and pipe-in only these selected keywords into the next question?
Yes, it is possible. If I were doing it I would add an addOnPageSubmit function to your text question. Have the function use regex to find and store all the matches in an array. Then randomly select an element from the array and save it to an embedded variable. On the next question (on the next page), all you have to do is pipe the embedded variable into the question and add some display logic to only show the question if the embedded variable is not empty.

> Finally, where would you add this JavaScript code when building the survey? Would it be through the "Add JavaScript" function or would I need to access the back-end of the survey to change this?
Use "Add JavaScript" on your text entry question.

Leave a Reply