Mod question text based on previous choice - did I do it the right way? | XM Community
Solved

Mod question text based on previous choice - did I do it the right way?

  • 17 January 2018
  • 3 replies
  • 39 views

Userlevel 2
Badge +2
Greetings --

I'm pretty pleased with the answer I came up with for a researcher this morning -- I used branching and embedded data to change the text of a subsequent question.

!


The "Surname" ED variable is inserted in the text of a subsequent question so that "Ryan's" last name is either Smith or Jones.

On preview, it works -- but is it the most elegant solution? Do I need to have all those branches?
icon

Best answer by TomG 17 January 2018, 18:46

View original

3 replies

Userlevel 7
Badge +27
If applicable, you can eliminate one branch by setting a default value. Using your example:
Surname = Smith
If Red is selected:
Surname = Jones
Userlevel 2
Badge +2
We have many (>10) choices and corresponding text strings, so it looks like I was probably on the right track -- but thanks for reminding me about the Default @TomG!
Userlevel 7
Badge +27
Since you have a lot of choices, an alternative would be to use JavaScript to do the replacement (if you know how to code in JavaScript). The basic steps would be:
1. Add a span tag with an id where you want to do the replacement - `<span id='replaceThis'></span>`
2. Setup an array in JS (e.g. arr) with your replacement text corresponding to recode values of the question you are basing it on (recoding the choices starting with 0 makes this easier)
3. Pipe the selected recode into a JS variable (e.g. recode)
4. Update the innerHTML of the span tag with the appropriate array value (e.g. arr[recode])
5. Optionally, set an embedded variable to the appropriate array value if you want a record of what the replacement was

Leave a Reply