Highlight Question type inside a Loop & Merge block | XM Community
Skip to main content

 I have a question about using a Highlight question inside a Loop&Merge block.
When I place the L&M field ${lm://Field/1} in the highlight text box it treats it as a literal and not a L&M variable. Is there a way to do what we want (JS or otherwise)?

Yes, you have to use JS to change the contents.


Hi Tom--
Thanks for getting back to me!
I used this script to write a Loop & Merge variable to my Highlight Q placeholders ".":
Qualtrics.SurveyEngine.addOnReady(function () {
  var $this = jQuery(this.questionContainer);
var test_text = "${lm://Field/1}";
  var choices = test_text.split(" ");
  jQuery(".QuestionBody .HLTextWords .HLTextWord", $this).each(function (i) {
    jQuery(this).text(choicesxi].trim());
  });
});
However, as you can see from the below screenshot, "${lm://Field/1}" loses its formatting from being 4 paragraphs to all being joined together (and includes some html tags!) , AND there is a series of trailing "." HLTextWord "boxes".
Is there any way to remedy these two remaining issues?

image.png


https://community.qualtrics.com/XMcommunity/discussion/comment/42332#Comment_42332You should replace the


tags with spaces before splitting the string.
  • You should hide a span if you don't have a word to put in it


  • https://community.qualtrics.com/XMcommunity/discussion/comment/42332#Comment_42332Hi Graeme,
    Thank you so much for sharing your code.
    I also tried to incorporate the loop-and-merge sentences in the "edit this highlight text" field, and I used your JS code, but it does not work for me. In the preview it basically shows me a blank field and nothing to highlight. Can I ask you whether you somehow defined the Embedded data or did anything else besides this js code?
    Thanks!


    Hi OG--
    I put the L&M sentences in the L&M field window(s)
    I put periods separated by single spaces in the "edit this highlight text" field, i.e: . . . . . . . . . .
    When I previewed I made sure I used "Preview" and not "Preview Block".
    I was not able to do any formatting (carriage returns, etc.) nor hide the "extra' spans as Tom suggested, although I tried to, with the last line of the below code:
    Sorry I can't be of more help!
    (Screenshots below the code)
    Qualtrics.SurveyEngine.addOnReady(function ()
      var $this = jQuery(this.questionContainer);
      var test_text = "${lm://Field/1}";
      var choices = test_text.split(" ");
      jQuery(".QuestionBody .HLTextWords .HLTextWord", $this).each(function (i) {
        if(choicesi]) { jQuery(this).text(choicesti].trim()); }
        else { jQuery(this).hide; }
      });
    });
    Highlight Q Screenshots.png


    https://community.qualtrics.com/XMcommunity/discussion/comment/50250#Comment_50250__OG__ started a new thread and I answered the question:
    https://community.qualtrics.com/XMcommunity/discussion/22423/highlight-question-and-loop-and-merge


    Thanks a lot, both of you! Yes, indeed, TomG resolved my issue in a separate thread! Thanks!


    Leave a Reply