Carrying forward selected choices and displaying additional information specific to each choice | XM Community
Solved

Carrying forward selected choices and displaying additional information specific to each choice

  • 8 August 2019
  • 1 reply
  • 14 views

Badge
Hi!

I'm setting up a study on medical decision-making, but I am having issues with a task I'm trying to present to my participants.
I put together a task consisting of two rounds. In the first one, participants have to choose from a number of medical diagnostic tests they would like to run in order to diagnose a patient in a previously presented case study (multiple choices possible).
After they make their choices, only the selected choices should be carried over to the next screen (different question and block), and presented.
However, for each selected & carried over choice I'd like to present the outcome of the test in addition (a text containing predetermined information on the outcome of the test).

I tried making this work with carrying forward choices, but it does not work as I can't edit the choice text that has been carried over.
I think it would be impossible to do this manually with branching or display logic, as the number of choices is 21, with all combinations possible.
Loop and merge would also not work, given the large number of possible combinations, and the nature of the task.

The optimal way would probably be creating a sort of lookup table in JavaScript, containing 2 columns - an identifier for each possible choice in the first stage (first option is 1, second is 2. etc.) , and a corresponding text for each, that can be matched with selected choices and presented with piped text.
(similar to this code, from GitHub).

I'd like to ask the community if someone has had experience with a similar problem in the past, and found a built-in solution in Qualtrics?
Alternatively, if someone has JavaScript code on hand that worked for similar issues, I'd be very grateful for sharing!


I attached the (dummy) images below to illustrate my issue:

Input:
!

Desired output:
!

Thanks in advance for any help & advice!

Cheers,
Daniel
icon

Best answer by dkaszas 8 August 2019, 19:39

View original

1 reply

Badge
I got it to work with the following code – it's messy, but it seems to do the job for now.






Qualtrics.SurveyEngine.addOnload(function()
{

/* define the empty embedded data variable TEXT at the beginning of survey flow & calculate recoded_choices embedded data from survey answers*/

var textoptions = ['<br>blood results text <br>', '<br>urine result text <br>','<br>glucose results text<br>', '<br>natrium results text<b>'] /*this establishes the results vector*/


var index = "${e://Field/recoded_choices}"; /*pipe in emb. data var., with choices recoded sequentially to match index, starting with 0 */


var result = []; /* loop to subset out matching text for each index selected*/

for(var i=0; i<textoptions.length; i++) {

var index_loop = index[i];
result.push(textoptions[index_loop]);
}



Qualtrics.SurveyEngine.setEmbeddedData('TEXT', result); /*push to Qualtrics*/




});

Leave a Reply