Carry forward response into Drag & Drop box | XM Community
Solved

Carry forward response into Drag & Drop box

  • 18 February 2021
  • 4 replies
  • 26 views

Badge

Hello,
For my survey:
Q1 is a Matrix Table Likert "Drag and Drop" question where respondents are shown a list of 20 statements and asked to sort them equally into 2 groups (Group A & Group 😎.
Q2 is a similar question except it carries forward the statements dropped into Group A, and respondents are asked to further sort those into 2 groups (Group A.1 & Group A.2)
Q3 asked them to do the same thing (Sort carried forward statements from Group B into Group B.1 & Group B.2).
I have managed to do till then. The difficulty I am having is for Q4, where I need to show Groups A.1, A.2, B.1 and B.2 and ask the respondents if they are happy with their groups or if they wish to change. I can't seem to bring forward the selected statements and display them within he correct box as per the image below.
Screenshot 2021-02-18 at 3.03.37 PM.pngQualtrics Support told me that I would need to insert a Javascript in order to do this, and I am unsure as to how I should. I will really appreciate it if someone is able to help me with this.

Thank you!

icon

Best answer by ahmedA 18 February 2021, 15:32

View original

4 replies

Userlevel 7
Badge +21

This code should work for you:
Qualtrics.SurveyEngine.addOnReady(function () {
    let ques = this;
    let a1 = "${q://##QID of A##/ChoiceGroup/SelectedChoicesForAnswer/1}";
    let a2 = "${q://##QID of A##/ChoiceGroup/SelectedChoicesForAnswer/2}";
    let b1 = "${q://##QID of B##/ChoiceGroup/SelectedChoicesForAnswer/1}";
    let b2 = "${q://##QID of B##/ChoiceGroup/SelectedChoicesForAnswer/2}";

    let choice_text = ques.getChoiceContainer().innerText.split(/\\n/gm);
    let all_choices = ques.getChoices();
    let all_answers = ques.getAnswers();

    for (let i = 0; i < choice_text.length; i++) {
        let set_choice = -1;
        switch (true) {
            case a1.includes(choice_text[i]):
                set_choice = all_answers[0];
                break;
            case a2.includes(choice_text[i]):
                set_choice = all_answers[1];
                break;
            case b1.includes(choice_text[i]):
                set_choice = all_answers[2];
                break;
            case b2.includes(choice_text[i]):
                set_choice = all_answers[3];
                break;
        }
        ques.setChoiceValue(all_choices[i], set_choice, true);
    }
});

Points to note:

  1. ##QID of A##
    and
    ##QID of A##
    refer to questions where you are asking them to sort answers in A1, A2 and B1, B2.

  2. Your scale points in this question should be in the order A1, A2, B1, B2. The name doesn't matter.

  3. Your statements should be all the statements from both the questions. The order doesn't matter.

Badge

Hi ahmedA,

Thank you so much for helping with the code.
I followed exactly what you said but somehow it's not working exactly.
This is the code:
Screenshot 2021-02-19 at 11.17.49 AM.pngYet when I run it, nothing appears in the groups
Screenshot 2021-02-19 at 11.17.22 AM.pngAm I doing anything wrong perhaps?

Badge

Hi ahmedA,

I actually managed to get it to work. I realised I had to set it carry forward all the statements from the Q1 to Q4, and then when I ran the javascript, it automatically sorted it.

Thank you so much for your help!

Badge +2

Can I ask how you carried forward the statements after first sorting them into groups? E.g. I need to ask participants sort 46 statements into agree more, neutral, or agree less. Then I'd like to carry forward the statements within each category (agree more, neutral, and agree less) and then have them rank each statement from -5 to 5, where -5 to -1 is for the agree less pile, 0 is neutral and 1 to 5 is for the agree more pile.

Leave a Reply