Display logic within question possible? | XM Community
Skip to main content
Solved

Display logic within question possible?


Forum|alt.badge.img+2

I have a Loop Merge set of questions.  However if there is only 1 loop necessary, I want the language to omit the Loop and Merge Field1 and Field2 without having to create 2 sets of questions.

 

What is the age of the ${lm://Field/1}${lm://Field/2} child?

If only 1 child: What is the age of the child?

 

If more than 1 child: What is the age of the 1st child?…. What is the age of the 2nd child?

Best answer by TomG

@Rhaven Nelson,

You can do it with a bit of JS. Assuming you captured the number of children in a previous question, you can do the following.

Question html:

What is the age of the <span class="ordinal">${lm://Field/1}${lm://Field/2}</span> child?

JS:

Qualtrics.SurveyEngine.addOnload(function() {
  if("{pipe number of children here}"=="1") {
    jQuery("#"+this.questionId+" .ordinal").hide();
  }
});

 

View original

3 replies

vgayraud
QPN Level 5 ●●●●●
Forum|alt.badge.img+48
  • QPN Level 5 ●●●●●
  • 366 replies
  • December 15, 2023

Hi @Rhaven Nelson , you could try this :

Qualtrics.SurveyEngine.addOnReady(function()
{
	/*Place your JavaScript here to run when the page is fully displayed*/

	var totalLoops ="${lm://TotalLoops}";
	if (totalLoops == 1) {
		jQuery("#"+this.questionId+" .QuestionText").html("What is the age of the child?");
	}

});

 


TomG
Level 8 ●●●●●●●●
Forum|alt.badge.img+27
  • Level 8 ●●●●●●●●
  • 5926 replies
  • Answer
  • December 15, 2023

@Rhaven Nelson,

You can do it with a bit of JS. Assuming you captured the number of children in a previous question, you can do the following.

Question html:

What is the age of the <span class="ordinal">${lm://Field/1}${lm://Field/2}</span> child?

JS:

Qualtrics.SurveyEngine.addOnload(function() {
  if("{pipe number of children here}"=="1") {
    jQuery("#"+this.questionId+" .ordinal").hide();
  }
});

 


Forum|alt.badge.img+2
  • Author
  • Level 2 ●●
  • 14 replies
  • January 10, 2024

Thank you!!


Leave a Reply