1

I have a question with 5 choices (A,B,C,D,E), displayed in random order. Say for a particular user they are displayed in the order C, D, A, E, B

I want to set embedded data field "Output" based on the displayed order of the selected choice. In the above example: if the user chose C, I want Output = 1; if the user chose E, output = 4 and so on.

(Similarly, if the displayed order was A,D,C,B,E - if the user chose C, output = 3 etc). User can select only one choice.

What is a good way to implement this?

I tried the following, but it sets Output to the order of choices listed in the question, not the displayed order.

this.questionclick = function(event,element)
    {
        console.log(event,element);
        if (element.type == 'radio')
    {
        var choiceNum = element.id.split('~')[2];
       
       Qualtrics.SurveyEngine.setEmbeddedData("Output", choiceNum);
       
    }

Thanks!

  • 1
    why not take the letter as result? – Nina Scholz Mar 16 '23 at 19:17
  • 1
    @NinaScholz : I also want the order in which that letter was displayed. The subsequent flow of the survey will depend upon both a) the selected choice and b) whether the selected choice was the top displayed choice or the second etc. It is necessary for the design of my experiment. – user20380762 Mar 16 '23 at 19:21

1 Answers1

0

All that matters is which choice is selected when you click Next. So, you can do this:

Qualtrics.SurveyEngine.addOnPageSubmit(function() {
  jQuery("#"+this.questionId+" [type=radio]").each(function(i) {
    if(this.checked) {
      Qualtrics.SurveyEngine.setEmbeddedData("Output",i+1);
      return false;
    }
  });
});
T. Gibbons
  • 4,919
  • 2
  • 15
  • 32