Count Selected Choices with JavaScript | XM Community
Skip to main content
Hello,



I have a multiple choice question where you can submit multiple answers.

I want to count the number of answers selected in a previous question and save it in an embedded data field for later use. The first part of this is what I am having problems with.



I have got to the point where I can save the text of the choices, but not yet any further: ${q://QID368/ChoiceGroup/SelectedChoices}

This displays (when used as piped text in a later question) the text of the checked answers, but I just want to count them.



Is there a documentation which contains all the possible branches/elements behind ChoiceGroup/... or even QID368/... etc. ?

Also I don't quite know where to debug/fiddle with things in general. Currently I use the Firefox console, where I could view the JavaScript code of my question (due to an error I believe). But now I can't access that anymore.



I am new Qualtrics and have little experience with JavaScript.



Thanks for any help!
@CanerLC there is documention on this in Qualtrics Support.



Check out this page: https://www.qualtrics.com/support/survey-platform/survey-module/editing-questions/piped-text/piped-text-overview/



The very bottom has a QTip that shows you the code for piping in choice count:



Qtip: This option is not in the Piped Text menu. The format for the Selected Count Piped Text is ${q://QIDX/SelectedChoicesCount}. For example, if you want to show the number of selected answers for Q12, it’d be ${q://QID12/SelectedChoicesCount}. If Q12 is a Matrix Table and you want Selected Count for the second statement, the Piped Text is ${q://QID12/SelectedChoicesCount/2}.
Thank you very much. This helps me a lot!
As to your second question, use Chrome developer tools for debugging.

Leave a Reply