How to pipe text from loop and merge into highlight question | XM Community
Skip to main content

I’m hoping someone can help me fix this problem. I have hundreds of text excerpts that I would like to present to participants in the highlight question type, so they can highlight parts of the text that seem warm vs. not warm.
 

I pasted the different text into the loop and merge field (toy data for example):

 

I added this bit of JS code to the block: 

Qualtrics.SurveyEngine.addOnload(

function () {

var words = "${lm://Field/2}".split(" ");

jQuery("#"+this.questionId+" .HLTextWord").each(function(i) {

jQuery(this).text(words(i]);


});

}

);

And then I entered ${lm://Field/2} into the “edit highlight text section”:

 

But when I preview the question, only the first word of Field 2 appears:

 

How do I get the text to pipe properly with each word as it’s own highlightable section? I’m not very familiar with JavaScript so I’d appreciate that if I needed to change my code that someone could help me identify those exact changes. Thank you!

@rondalo I can see what you’re trying to do following previous thread. However, you don’t get the full picture of this. Your code should look like this:

Qualtrics.SurveyEngine.addOnload(function () {
var words = "${lm://Field/2}".split(" ");
jQuery("#"+this.questionId+" .HLTextWord").each(function(i) {
if(i < words.length) jQuery(this).text(words(i]);
else jQuery(this).hide();
});
});

In the question, you have to set this up as container to hold your text (the number should cover the longest number of words in your sentences)

Hope this helps


@dxconnamnguyen Thank you so much for your help! It worked! 

 

 

 


@dxconnamnguyen Thank you so much for your help! It worked! 

@rondalo Happy to help 👍


Leave a Reply