Hiding Questions Based on Loop and Merge Values in Qualtrics | XM Community
Skip to main content

Hello Qualtrics Community!

I’m currently working on a survey in Qualtrics that involves Loop and Merge functionality, and I'm trying to conditionally hide a question based on the value of a Loop and Merge field. However, I'm facing some challenge getting it to work as intended.

Here’s what I’ve implemented so far:

Qualtrics.SurveyEngine.addOnload(function() {

jQuery("#QID119").hide();

var fieldValue = "${lm://Field/3}";
var featuresValue = "${e://Field/features}";

console.log("Field Value:", fieldValue);
console.log("Features Value:", featuresValue);

if (fieldValue === "1" && featuresValue === "multi") {
jQuery("#QID119").show();
}
});

My Current Issue:

  • Despite hiding the question initially, it still shows up even when the Loop and Merge value does not match my specified condition.
  • I want to ensure that the question remains hidden unless the Loop and Merge value meets specific criteria.

Additional Details:

  • The question ID is confirmed to be correct.
  • I have tested with hardcoded values for the condition, but it still does not behave as expected.

Questions for the Community:

  1. Has anyone experienced similar issues with hiding questions based on Loop and Merge values?
  2. Are there any known pitfalls or best practices I should be aware of when using JavaScript for this purpose in Qualtrics?

Thank you for your help in advance! I appreciate any guidance or suggestions you might have.

@raholini 

Additional Details:

  • The question ID is confirmed to be correct.

Yes but in Loop&Merge, your question ID will be cloned by the number of loops. For example: If you have 4 loop then the QID will be: 1_QID119, 2_QID119, 3_QID119, 4_QID119. So you should use ${lm://CurrentLoopNumber} to findout the right one that you want to hide.


Thanks a lot, @Nam Nguyen!

I updated my JavaScript code based on your suggestion, and it seems to be working as intended. I’ve included the code below in case it’s helpful to others.

Qualtrics.SurveyEngine.addOnload(function() {
// Get the current loop number
var currentLoopNumber = "${lm://CurrentLoopNumber}";

// Construct the question ID for this specific loop iteration
var questionID = currentLoopNumber + "_QID119";

// Hide the question initially
jQuery("#" + questionID).hide();

// Fetch the Loop & Merge and embedded field values
var fieldValue = "${lm://Field/3}";
var featuresValue = "${e://Field/features}";

// Show the question only if the specified condition is met
if (fieldValue === "1" && featuresValue === "multi") {
jQuery("#" + questionID).show();
}
});

 


@raholini Great, glad I could help 👍

  1. Are there any known pitfalls or best practices I should be aware of when using JavaScript for this purpose in Qualtrics?

By the way, you seem to know coding so just put a lot of console log in your code to know what’s triggered and what’s not. Inspect the element in Dev mode F12 and you will be good.


Thanks a lot, @Nam Nguyen!

I updated my JavaScript code based on your suggestion, and it seems to be working as intended. I’ve included the code below in case it’s helpful to others.

Qualtrics.SurveyEngine.addOnload(function() {
// Get the current loop number
var currentLoopNumber = "${lm://CurrentLoopNumber}";

// Construct the question ID for this specific loop iteration
var questionID = currentLoopNumber + "_QID119";

// Hide the question initially
jQuery("#" + questionID).hide();

// Fetch the Loop & Merge and embedded field values
var fieldValue = "${lm://Field/3}";
var featuresValue = "${e://Field/features}";

// Show the question only if the specified condition is met
if (fieldValue === "1" && featuresValue === "multi") {
jQuery("#" + questionID).show();
}
});

 

@raholini, your code will be really helpful to our Community. Thanks for sharing!


Leave a Reply