Add formatting to javascript title? | XM Community
Skip to main content

I have a title of a question that is dynamic based on previous answers. I need one of the static words to be bolded and put additional question information on the next line in a smaller case. I am able to pipe the correct values I need in javascript I am just unable to format the rest of it. Any help is appreciated. If the answer is css, how can I apply css format to static words?

This is what I have so far:

  // Retrieve the answer of the field question
  var fieldAnswerValue = "${e://Feild/Entity}";

    
      // Retrieve the response from the follow-up question
  var followUpResponseValue = "${e://Field/OtherEntity}";

      // Specify the default question title
  var defaultQuestionTitle = "Does {$Other} collect <static bold text>?"
    // Define the additional line text
  var additionalLineText = "Additional information."; < I need this on a new line with a smaller font. <br> and <span> isn’t working>

    // Combine the question title and additional line text
  var defaultQuestionTitle = defaultQuestionTitle + additionalLineText;


      // Define the dynamic question title based on the field answer
  var dynamicQuestionTitle;

  if (fieldAnswerValue === 'Other') {
    // Pipe the response from the follow-up question
    dynamicQuestionTitle = defaultQuestionTitle.replace('{$Other}', followUpResponseValue);
  } else {
    // Use the field answer as the question title
    dynamicQuestionTitle = defaultQuestionTitle.replace('{$Other}', fieldAnswerValue);
  }

  // Set the dynamic question title
    qt = this.getQuestionContainer().querySelector(".QuestionText");
    qt.innerText = dynamicQuestionTitle ;

@ChrsCrager 

Update your last line to   -   qt.innerHTML = dynamicQuestionTitle ;

And then use <br> or <b> to update style.

Hope this helps!


Leave a Reply