Randomizing groups of questions within a block | XM Community
Skip to main content
Solved

Randomizing groups of questions within a block


Forum|alt.badge.img+2
  • Level 2 ●●
  • 32 replies

I have the following setup in Qualtrics: 

Statement 1

Question 1.1

Question 1.2 

Question 1.3 

Question 2.1 

Question 2.2

Question 2.3 

Question 3.1

Question 3.2

Question 3.3

 

I have them all in one block because all the questions needs to be displayed in one page. 

 

I want to randomize questions 1, 2 and 3. 

This means Q1.1, Q1.2 and Q1.3 will appear together always. Similarly Q2.1, Q2.2 and Q2.3 will appear together. And finally, Q3.1, Q3.2 and Q3.3 will appear together. But the sequence in which the question groups (Q1, Q2 and Q3)  appear will vary. 

For example one respondent will see the question sequence as below:

Statement 1

Question 2.1

Question 2.2 

Question 2.3 

Question 1.1 

Question 1.2

Question 1.3 

Question 3.1

Question 3.2

Question 3.3

 

Please let me know. 

 

Thanks, 

O

Best answer by TomG

@OBh,

Use Advanced Randomization so that Q1, Q2, and Q3 are randomly displayed immediately after “Statement”.

Add a span with a class to associate each of the follow-up questions with the parent question. For example:

<span class="Q1">(1) I agree with the statement</span>

Add JS to the parent questions to move their follow-up questions immediately after. For example:

Qualtrics.SurveyEngine.addOnload(function() {
	var q = jQuery(this.questionContainer);
	jQuery(".Q1").each(function() { jQuery(this).closest(".QuestionOuter").insertAfter(q); });
});

 

View original

17 replies

  • Level 4 ●●●●
  • 208 replies
  • March 7, 2025

Can you show how did you set the question. Images will be more beneficial.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • March 7, 2025

@OBh,

Question randomization alone can’t do this. You could combine question advanced randomization together with JS that moves questions to accomplish it.


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 7, 2025

@TomG sorry, I do not know what JS to use for this. I can do advanced randomization but that does not allow grouping. So, it would be helpful if you could elaborate. 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 7, 2025

@jbk 

 

Please see the image below, they are all multiple choice questions. 

 


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • Answer
  • March 7, 2025

@OBh,

Use Advanced Randomization so that Q1, Q2, and Q3 are randomly displayed immediately after “Statement”.

Add a span with a class to associate each of the follow-up questions with the parent question. For example:

<span class="Q1">(1) I agree with the statement</span>

Add JS to the parent questions to move their follow-up questions immediately after. For example:

Qualtrics.SurveyEngine.addOnload(function() {
	var q = jQuery(this.questionContainer);
	jQuery(".Q1").each(function() { jQuery(this).closest(".QuestionOuter").insertAfter(q); });
});

 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 7, 2025

@TomG 

Thanks for the suggestion. I will use this to try and build a working solution. 

Thanks, 

O


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 9, 2025

@TomG 

 

Thanks it worked.

I was a mistake of using the same class to both statements .

So I used <span class="Q1_1"> and <span class="Q1_2"> and then used the code you have provided :
 

Qualtrics.SurveyEngine.addOnload(function() {
    var q = jQuery(this.getQuestionContainer());


    jQuery(".Q1_1").each(function() { 
        jQuery(this).closest(".QuestionOuter").insertAfter(q);
        q = jQuery(this).closest(".QuestionOuter"); 
    });

    jQuery(".Q1_2").each(function() { 
        jQuery(this).closest(".QuestionOuter").insertAfter(q);
        q = jQuery(this).closest(".QuestionOuter"); 
    });
});

Just in case anyone else is having trouble with such problems. 


 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 9, 2025

One more thing. I am unsure if it is possible in Qualtrics. 

My Question is: Suppose the main sequence of questions in the survey builder is: 

Q1: Statement 1: Local food is healthy
Q2: Statement 2: Local food is tasty
Q3: Statement 3: Local food is costly. 

When the randomization of questions groups occur, I want Q1, Q2 and Q3 to have have Statement i:………., where i depends on the position of the statement. Example. suppose after randomization the question sequence comes as: Q2,Q1 and Q3. 
So I wish the preview would be: 


Statement 1: Local food is tasty
Statement 2: Local food is healthy
Statement 3: Local food is costly. 

I gave it a try to put same class to all three statements Q1, Q2, Q3. 

<span class="statement-label"></span> . But unsure how to implement in JS to dynamically update it based on position. 

Any suggestion would be helpful. 

Thanks, 

O


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • March 10, 2025
OBh wrote:

@TomG 

 

Thanks it worked.

I was a mistake of using the same class to both statements .

So I used <span class="Q1_1"> and <span class="Q1_2"> and then used the code you have provided :
 

Qualtrics.SurveyEngine.addOnload(function() {
    var q = jQuery(this.getQuestionContainer());


    jQuery(".Q1_1").each(function() { 
        jQuery(this).closest(".QuestionOuter").insertAfter(q);
        q = jQuery(this).closest(".QuestionOuter"); 
    });

    jQuery(".Q1_2").each(function() { 
        jQuery(this).closest(".QuestionOuter").insertAfter(q);
        q = jQuery(this).closest(".QuestionOuter"); 
    });
});

Just in case anyone else is having trouble with such problems. 


 

You could have used the original code and just reversed the question order in advanced randomization.


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • March 10, 2025
OBh wrote:

One more thing. I am unsure if it is possible in Qualtrics. 

My Question is: Suppose the main sequence of questions in the survey builder is: 

Q1: Statement 1: Local food is healthy
Q2: Statement 2: Local food is tasty
Q3: Statement 3: Local food is costly. 

When the randomization of questions groups occur, I want Q1, Q2 and Q3 to have have Statement i:………., where i depends on the position of the statement. Example. suppose after randomization the question sequence comes as: Q2,Q1 and Q3. 
So I wish the preview would be: 


Statement 1: Local food is tasty
Statement 2: Local food is healthy
Statement 3: Local food is costly. 

I gave it a try to put same class to all three statements Q1, Q2, Q3. 

<span class="statement-label"></span> . But unsure how to implement in JS to dynamically update it based on position. 

Any suggestion would be helpful. 

Thanks, 

O

Assuming you are adding it to the previous code:

q.find(".statement-label").function(i) { jQuery(this).text(i+1); });

 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 11, 2025

@TomG Thanks for your response. 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 17, 2025

@TomG 

A follow up. I used the following code: 

 

Qualtrics.SurveyEngine.addOnload(function() {
    var q = jQuery(this.getQuestionContainer());


    setTimeout(function() {
       
        jQuery(".Q1_1").each(function() { 
            jQuery(this).closest(".QuestionOuter").insertAfter(q);
            q = jQuery(this).closest(".QuestionOuter"); 
        });

        jQuery(".Q1_2").each(function() { 
            jQuery(this).closest(".QuestionOuter").insertAfter(q);
            q = jQuery(this).closest(".QuestionOuter"); 
        });

       
        q.find(".statement-label").each(function(i) { 
    jQuery(this).text(i + 1);
});

    }, 200); 
});

 

I put the class as: 
Statement <span class="statement-label"></span> Local food is costly

But the output is not putting any number after “Statement”. 

 


I used a more wordy approach:

 

 jQuery(".statement-label").each(function(i) {
            jQuery(this).text("Statement " + (i + 1) + ": ");


and used the parent question class as: <span class="statement-label"></span> Local food is costly
 

 

I am not sure where I am making error using the code you suggested. I used the logic you suggested in the wordy code. 

==================================================================


I had one more query. I am unsure if it is possible:


I would wish the following statements to show as:

(1) I agree with Statement 1
(2) Statement 1 is important to me

So, this “Statement #” will come dynamically on the two child questions depending on the parent question Statement #. 

Please let me know if it is possible.
Thanks, 

O


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 17, 2025

I tried like this:

<span class="Q1_1">
    (1) I agree with the Statement <span class="hash">#</span>
</span>

jQuery(".statement-label").each(function(index) {
             lastStatementNumber = index + 1
            jQuery(this).text("Statement " + (index + 1) + ": ");
});

jQuery(this).text(currentText.replace("#", lastStatementNumber));

But there are two problems happening:

​​​​ ​1. Every # is getting replaced by 1. 

2.The  sequence of child questions randomization is getting messed up. 


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • March 18, 2025

@OBh

Try this simplified approach that works:

  • Use Question Randomization to randomize the statements and reverse the order of the follow-up questions. For example:
  • Modify the question text of the follow-up questions to tie them to their statement. For example:

<span class="Q1">Q1 MC 1</span>
  • Modify the question text of the statements to allow for numbering. For example:
<span class="statement-label"></span> Q1
  • Add this JS to the first statement (e.g., Q1):
Qualtrics.SurveyEngine.addOnload(function() {
	var q = jQuery(this.questionContainer);
	jQuery(".Q1").each(function() { jQuery(this).closest(".QuestionOuter").insertAfter(q); });

	jQuery(".statement-label").each(function(i) { jQuery(this).text("Statement "+(i+1)+":"); });
});
  • For the other statements add the same JS, but remove the last line of code and change the class name in the selector:
Qualtrics.SurveyEngine.addOnload(function() {
	var q = jQuery(this.questionContainer);
	jQuery(".Q2").each(function() { jQuery(this).closest(".QuestionOuter").insertAfter(q); });
});

The result:

 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 18, 2025

@TomG thank you so much for your detailed response. I do not think this will change the following child questions to the parent questions right? 

 

I would wish the following statements to show as:

Statement 1: Q3

(1) I agree with Statement 1
(2) Statement 1 is important to me

 

The Statement # in (1) and (2) will follow the statement # in the parent question. 


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • March 18, 2025
OBh wrote:

@TomG thank you so much for your detailed response. I do not think this will change the following child questions to the parent questions right? 

 

I would wish the following statements to show as:

Statement 1: Q3

(1) I agree with Statement 1
(2) Statement 1 is important to me

 

The Statement # in (1) and (2) will follow the statement # in the parent question. 

Ok, use some other class for the follow-up statements (e.g., statement), move the “:” outside the span, and change the JS a bit:

Q1:

Qualtrics.SurveyEngine.addOnload(function() {
    jQuery(".statement-label").each(function(i) { jQuery(this).text("Statement "+(i+1));
});

Qualtrics.SurveyEngine.addOnReady(function() {
	var q = jQuery(this.questionContainer);
    var stmt = q.find(".statement-label").text()
	jQuery(".Q1").each(function() { 
      jQuery(this).closest(".QuestionOuter").insertAfter(q).find(".statement").text(stmt);      
    });
});

On the other statements, you only need the addOnReady function. Change “.Q1” as appropriate.


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 32 replies
  • March 19, 2025

@TomG thanks for your response. Will try this approach. 


Leave a Reply