Hello,
I have a PGR question that gives respondents 12 items, asks them to add as many as they want to a group, and then rank those (there's only one group). I need to set just the three highest ranked items as embedded data to be asked about later. It would be easier to work with the values instead of the labels, but either is fine.
This question (https://community.qualtrics.com/XMcommunity/discussion/14303/rank-order-carry-forward-using-embedded-data) showed how to set the top three items from a Rank Order question as embedded data.
This question (https://community.qualtrics.com/XMcommunity/discussion/16799/saving-pick-group-rank-responses-to-embedded-data-with-javascript) showed how to set PGR group responses as embedded data, but in my testing it doesn't always select the three highest ranked items.
I'm trying to do a combination of these tasks. I'm very new to Javascript and am having a hard time figuring it out.
Thank you in advance for any help.
This will give you the choice ids of the three highest ranked items:
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
jQuery("#"+this.questionId+" .Group li").each(function(i) {
if(i<3) Qualtrics.SurveyEngine.setEmbeddedData("rank"+(i+1),jQuery(this).attr("data-choiceid"));
});
});
@TomG, you nailed it! Thank you!
And now I see I can edit it to this if I wanted to set the labels as ED instead:
Qualtrics.SurveyEngine.addOnPageSubmit(function() {
jQuery("#"+this.questionId+" .Group li").each(function(i) {
if(i<3) Qualtrics.SurveyEngine.setEmbeddedData("rank"+(i+1),jQuery(this).find("labellfor]").text().trim());
});
});
Very helpful. Thanks again!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.