How to pipe seperate selected choices from one multiple choice question to compare them | XM Community
Solved

How to pipe seperate selected choices from one multiple choice question to compare them


Hi everyone I hope someone can help me with this.
So I have a multiple choice question where people are forced to choose 4 answers from a list of 12 choices.
Now in a the next question, I want to compare the selected choices with each other. So if a person choose for example banana, apple, pear and cherry from a list of fruit, I would want to ask them how apples compare to pears, then how apples compare to bananas and finally to cherries.
So I would ideally like to have a line to pipe each selected answer from 1 question individually, and not all at the same time like ${q://QID62/ChoiceGroup/SelectedChoices} or the carry over function does. Is there a way to pipe 'selected answer 1', 'selected answer 2' etc. seperately?

icon

Best answer by rondev 24 April 2020, 13:24

View original

14 replies

Userlevel 7
Badge +22

Create four embedded data in the survey flow and using JS assign these embedded data with selected values of MC question. Pipe these embedded data in question as required.

Can you explain what the JS code would look like? This closely matches what I need as well, but I have no idea how to program JS...

Userlevel 7
Badge +22

On the click of next button find all the text of selected check boxes and store them in array, loop the array and store it in embedded data.

Hey thanks for the answer. So I tried this code, using another thread (https://www.qualtrics.com/community/discussion/4376/ho-to-display-only-one-unselected-choice-using-piped-text):
code.pngAnd created embedded variables K1,K2,K3 and K4.
But when I try to pipe these embedded variables using for example ${e://Field/K1} it doesn't seem to be working, I just get an empty space.
Any idea what's going wrong?

Userlevel 7
Badge +22

The code is correct except the line - var rank = ......... ; here their is an extra '}' just remove one. Also, this code will run on next page any questions JS part. Make sure you have created four embedded data at the beginning of the survey.
Below is the method 2, this code needs to be pasted on the same MC question (unlike previous one). First, go to recode values and check variable naming option and click close. Paste the below code in the JS part of the MC question (the code will only run if the selection is equal to 4, hence make sure you have set the custom validation properly)

Qualtrics.SurveyEngine.addOnPageSubmit(function(type)
{
var that = this;
if(type == "next")
{
var arr = that.getSelectedChoices();
var ed = ["k1","k2","k3","k4"];
if(arr.length == 4){

for(var i = 0;i Qualtrics.SurveyEngine.setEmbeddedData(ed[i],that.getChoiceVariableName ( parseInt(arr[i]) ) );
}
}
}
});

Thank you very much for your time and code! It's working now!

Badge

Hi rondev,
I'm trying to pipe in answers from a multiple choice question to a constant sum question. I've added the following code in the Javascript in the constant sum question. However, I still get blank fields. Can you please help to point out what I'm doing wrong? Do I need to create embedded data? Or is there something wrong with the code?
Thanks in advance!
Screenshot 2022-03-17 at 14.06.02.png

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/44651#Comment_44651Piped data gets resolved on the server before the page is sent to the browser. So, you can't set embedded data fields and pipe them on the same page (the values have already been piped before you set them).

Badge

https://community.qualtrics.com/XMcommunity/discussion/comment/44655#Comment_44655Hi TomG, thanks for explaining! Any suggestions on what shall I do to pipe the answers from the previous question in a constant sum question?

Userlevel 7
Badge +27

https://community.qualtrics.com/XMcommunity/discussion/comment/44677#Comment_44677I'm not exactly sure what you are attempting, but normally you would just carry forward the selected choices from the MC question into the Constant Sum question. No JS required.

Badge

https://community.qualtrics.com/XMcommunity/discussion/comment/44686#Comment_44686Currently I add this ${q://QID144/ChoiceGroup/SelectedChoices} but it would show all the answers from the previous question. I'm trying to pipe in one answer option per the constant sum row. Something like on the below screen. I know that the code might not be correct.
Screenshot 2022-03-18 at 12.42.57.png

Userlevel 7
Badge +27

AdWrld ,
You misunderstood my meaning. Use carry forward instead of piping and JS. It would look like this:
image.png

Badge

https://community.qualtrics.com/XMcommunity/discussion/comment/44746#Comment_44746This is genius, Tom!!! Thank you so much! 🤩

Userlevel 3
Badge +10

https://community.qualtrics.com/XMcommunity/discussion/comment/24531#Comment_24531hi roundv
your development seems to correspond in part to my problem that I posted here : https://community.qualtrics.com/XMcommunity/discussion/20725/export-matrix-table-responses-to-google-sheets
unfortunately I tried to use it by excluding the "if(arr.length == 4)" which does not concern my problem but I do not get any results in my embedded data

Leave a Reply