How to count # of items dragged & dropped into a box | XM Community
Solved

How to count # of items dragged & dropped into a box

  • 25 August 2018
  • 3 replies
  • 105 views

Hi. I have a question where there are 10 choices and they can be dragged or dropped into one of two boxes, or not. I need to be able to count how many are in one of the boxes because that number will be used later in the survey in a calculation. I can't seem to come up with an easy way to do it. Any help on this appreciated!
icon

Best answer by Anonymous 25 August 2018, 01:43

View original

3 replies

Userlevel 6
Badge +18
@Tom_R ,

You can use branch logic and embedded data as follows

!

!

!
Hello @Tom_R,

I hope you are using Pick, group, Rank question

Step 1: Add two embedded data (eg: Group1Count, Group2Count ) in the survey flow before the Pick, group, Rank question
Step 2: Add the following js in the `js(OnUnload)` of the pick group rank question

var group1count=jQuery("#" +this.questionId+"group0 li").length;
var group2count=jQuery("#" +this.questionId+"group1 li").length;

Qualtrics.SurveyEngine.setEmbeddedData( 'Group1Count', group1count );
Qualtrics.SurveyEngine.setEmbeddedData( 'Group2Count', group2count );

Step3: Use the embedded data (eg: Group1Count, Group2Count ) wherever required in the survey
> @Shashi said:
> Hello @Tom_R,
>
> I hope you are using Pick, group, Rank question
>
> Step 1: Add two embedded data (eg: Group1Count, Group2Count ) in the survey flow before the Pick, group, Rank question
> Step 2: Add the following js in the `js(OnUnload)` of the pick group rank question
>
> var group1count=jQuery("#" +this.questionId+"group0 li").length;
> var group2count=jQuery("#" +this.questionId+"group1 li").length;
>
> Qualtrics.SurveyEngine.setEmbeddedData( 'Group1Count', group1count );
> Qualtrics.SurveyEngine.setEmbeddedData( 'Group2Count', group2count );
>
> Step3: Use the embedded data (eg: Group1Count, Group2Count ) wherever required in the survey
>
>
>

Note: You can scale this solution i.e if you have more than two groups then you can create that many embedded data, and add variables in the js and change the code as: if you want group 3 count then change js as follows `var group3count=jQuery("#" +this.questionId+"group2 li").length;` , as group count starts with 0, hence -1.

Leave a Reply