Qualtrics: Transform piped variable using javascript and display it in text?
javascript, qualtrics
Solution
Use the `setEmbeddedData()` function to assign `selectedChoiceLower` to a new or existing embedded data variable (see documentation). Then, you can use the embedded field variable in a later question.
javascript: `setEmbeddedData('lower', selectedChoiceLower);`
embedded field code: `${e://Fields/lower}`
warning: putting user-generated text into your javascript is very dangerous! Qualtrics does not do any escaping. If a user puts a ' or " in their text, it will be put directly into the javascript and probably break your code. Code injection is also possible. See this question for more details.
Problem
Let there be a piped variable in qualtrics (a variable holding values recalled from a previous input by a survey respondent), how do I transform it to lower-case before displaying it? There is the java-script function `.toLowerCase();` but how do I change a variable in the qualtrics custom javascript and pipe it back into a survey text? This link explains how to use piped variables in javascript. Say I define a new variable in javascript like this ``` // my piped variable is ${q://QID12/ChoiceGroup/SelectedAnswers}" var selectedChoice = "${q://QID12/ChoiceGroup/SelectedAnswers}"; var selectedChoiceLower = selectedChoice.toLowerCase(); ``` How to pipe selectedChoiceLower back into a question text? Any ideas?