Piped Text Issue with Javascript | XM Community
Skip to main content
I ask respondents in a survey for their race and gender (in multiple choice questions). I then would like to use these answers, concatenate them with some other strings into a new variable, and then set that variable as embedded data to be used in another question.



So in the Javascript for a question on a page right after they have submitted the page asking for their race and gender, I pull in their answers using the piped text from the question:



`var gender="${q://QID245/ChoiceGroup/SelectedChoices}";`

`var race="${q://QID243/ChoiceGroup/SelectedChoices}";`



And then use those new variables in a new variable I have already initialized. For example:



`phrase="";`

`phrase="Some words " + race + " " + gender + " rest of phrase";`



And then, I simply set embedded data as normal. For some reason, when I then get to the question that's meant to use this embedded data, nothing at all shows up (whereas before, when the strings I set as embedded data were simply just phrases that did not rely on user input (e.g. phrase="Some words"), this all worked totally fine). I tried switching out the double quotations for single quotations, and have confirmed that the Piped Text ${q://QID245/ChoiceGroup/SelectedChoices} and ${q://QID243/ChoiceGroup/SelectedChoices} indeed work fine to pipe in their answers when included as question text ("Male" and "African-American", for example, show up entirely fine). I tried setting the race and gender variable to embedded data in the same code and they don't actually show up when included in question text later on in the survey, so it seems that the issue is in simply bringing in the answers to the Javascript, as in the first two lines above:



`var gender="${q://QID245/ChoiceGroup/SelectedChoices}";`

`var race="${q://QID243/ChoiceGroup/SelectedChoices}";`



I'm not sure what may be happening, and would appreciate any help! It's fairly critical I actually combine the strings with these answers in Javascript, as I am using these variables in a SBS question that I randomize myself, and not in question text (otherwise, the simple piping would work okay).
Hi all,



Upon further inspection, turns out that my answer choices in the multiple choice questions had CSS and additional formatting in them, which apparently messed up bringing them into the Javascript. Removing that formatting so that they indeed contained only the words did the trick.

Leave a Reply