Hi all,
I have a survey where I respondents listen to an audio clip and will need to answer questions about the audio clip. We also want respondents to be able to take notes about the audio clip while it is playing and use their notes to answer the questions. In order to prevent respondents from simply answering the questions while the audio clip is playing, I added a page break so the questions appear on the next page. However, we want participants to be able to use their notes from the previous page to answer the questions. One solution I found was to use the piped text function, piping the text from the notes (an essay text box entry) onto the next page. This has worked, except that the format of the notes is lost once it is piped onto the next page.
For example, if a respondent writes the following in their initial response:
qualtrics
text box entry
piped text format
It is piped onto the next page as:
qualtrics text box entry piped text format
The code I used for this was ${q://QID114/ChoiceTextEntryValue}.
Is it possible to add any custom code to keep the formatting of the response when it is piped onto the next page?
Any help is greatly appreciated. Thanks in advance!
I struggled with this problem for quite sometime and could figure out two solutions for it. I'm not happy with either of them as they preserve only some of the formatting and not all, but they may get the job done for you. Both require JS to capture the entered text:
Adding the "" tag to the text:
This is an HTML tag for pre-formatted text, so line breaks and spaces are preserved. But browsers have different display defaults for it:
Qualtrics.SurveyEngine.addOnPageSubmit(function(){
var text_value = this.getQuestionContainer().querySelector("textarea").value;
var text_value_pre = "
" + text_value + "";
Qualtrics.SurveyEngine.setEmbeddedData("text_value_pre",text_value_pre);
});
Now you can use the embedded variable
text_value_preto pipe the text anywhere.
Splitting the text and re-joining it: In this, one basically splits the text at a new line, stores it as an embedded variable. Then in the question where one wants to display it, re-joins the text:
In the text entry question:
Qualtrics.SurveyEngine.addOnPageSubmit(function(){
var text_value = this.getQuestionContainer().querySelector("textarea").value;
var text_value_split = text_value.replaceAll(/\\n/gm,"___");
Qualtrics.SurveyEngine.setEmbeddedData("text_value_split",text_value_split);
});
In the question, where you want to use the text, create an HTML div with some id like:
Will be Replaced
Now use JS to reformat the text and place it in the div.
Qualtrics.SurveyEngine.addOnReady(function(){
var text_value_split = "${e://Field/text_value_split}"
text_value_split = text_value_split.replaceAll("___",`
`);
this.getQuestionContainer().querySelector("#my_custom_text").innerText = text_value_split;
});
Note the use of backticks while replacing.
Demo.
Hi M_Baker , ahmedA ,
Just came across this thread and the bit of code - very ingenious. I just wanted to let you know that I have discovered that you don't need to do the JS code though. In the next question (on the next page) edit the question in HTML view and add
andsurrounding the piped text.
Just wondering under what cases would you then want to append
andto the embedded field?
Hope that's helpful
Thanks
Rod Pestell
The
element is stands for pre-formatted. So whenever you want to tell the browser not to format the given HTML, such as line breaks or multiple spaces, the element is useful.
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.