Including line breaks in piped text | XM Community
Skip to main content
Solved

Including line breaks in piped text

  • June 27, 2025
  • 2 replies
  • 75 views

Forum|alt.badge.img+1

Hello! 

 

I’ve seen previous posts about this topic, but I’m running into problems. I have a text box where respondents can edit a pre-written text. I am piping the resulting text (with respondents’ edits) to the end of my survey. The problem is that respondents can’t add line breaks.

 

This is my JS for Q1, based on this post: 

Qualtrics.SurveyEngine.addOnload(function() { 
// Get the text entry box
var textBox = jQuery("#" + this.getQuestionContainer().id + " .InputText");

// Pre-fill the text box with the passage
var prefilledText = "This is text that respondents can edit.";
textBox.val(prefilledText);

// Reassemble the text and update the text box
textBox.val(paragraphs.join("\n\n"));
});


/*Place your JavaScript here to run when the page loads*/
Qualtrics.SurveyEngine.addOnReady(function()
{
jQuery("#NextButton").click(function(){
var lines = jQuery("#QR\\~QID1").val().split("\n");
var inputText ="";
for(var i=0;i<lines.length;i++)
{
var inputText =inputText + lines[i];
if(i<lines.length-1)
{
var inputText =inputText + "<br>";
}
}
Qualtrics.SurveyEngine.addEmbeddedData("inputText", inputText); // Set value in hidden variable
});

});

 

This is my JS for Q4, based on this post:

 

Qualtrics.SurveyEngine.addOnload(function() { 
// Get the text entry box
var textBox = jQuery("#" + this.getQuestionContainer().id + " .InputText");

// Pre-fill the text box with the passage
var prefilledText = "This is text that respondents can edit.";
textBox.val(prefilledText);

// Reassemble the text and update the text box
textBox.val(paragraphs.join("\n\n"));
});


Qualtrics.SurveyEngine.addOnReady(function () {
const textBox = this.questionContainer.querySelector(".InputText");
textBox.oninput = function (a) {
const textEntry = a.target.value.replaceAll("\n", "<br>");
Qualtrics.SurveyEngine.setEmbeddedData("textEntry", textEntry);
};
});

 

This is my embedded data in the survey flow:

 

At the end of the survey, I’ve tried: ${q://QID1/ChoiceTextEntryValue}, ${e://Field/inputText}, ${q://QID4/ChoiceTextEntryValue}, and ${e://Field/textEntry}, which all give the edited text without any line breaks.

 

What should I do? Thank you!

Best answer by vgayraud

Hi,

You’re overwriting your EDs values with the original questions answers after setting them in your custom js code.

You should have empty EDs at the beginning of your survey flow, like this:

and then piping in ${e://Field/textEntry} in your block 2 should add the new line breaks correctly.

2 replies

vgayraud
QPN Level 6 ●●●●●●
Forum|alt.badge.img+58
  • QPN Level 6 ●●●●●●
  • 549 replies
  • Answer
  • July 1, 2025

Hi,

You’re overwriting your EDs values with the original questions answers after setting them in your custom js code.

You should have empty EDs at the beginning of your survey flow, like this:

and then piping in ${e://Field/textEntry} in your block 2 should add the new line breaks correctly.


Forum|alt.badge.img+1
  • Author
  • 2 replies
  • July 1, 2025

Thank you, ​@vgayraud!