I have an embedded data field I built with up to 20 items, separated by commas, and their estimated cost.
PSItemList = Item 1 $10 , Item 2 $20 , Item 3 $15
I would like to reformat PSItemList to show the items one per line in a vertical format instead. I tried various pieces of code from other posts, with no luck in getting any to work. I can either re-display the PSItemList embedded data field, or in my example, was trying to create a new field called PSReformList. All suggestions appreciated!
Qualtrics.SurveyEngine.addOnload(function()
{
var pipedText = "${e://Field/PSItemList}";
pipedList = pipedText.replace(/,/g, '\\n');
Qualtrics.SurveyEngine.setEmbeddedData("PSReformList",pipedList);
});
I'm not clear on where you are displaying the values. If it is on an html page, you either need to:
Use
instead of \\n
tag.
It's within a text question as the person is completing the survey, just a confirmation for them to double-check they entered the unit cost and unit prices they were expecting. Instead of a long list across, I'd like it to display down.
${e://Field/PSItemList} -OR-
${e://Field/PSReformList}
https://community.qualtrics.com/XMcommunity/discussion/comment/45022#Comment_45022Since that is the case, my previous comment applies. Either change "\\n" to "
" in your replace OR pipe it inside a
tag:${e://FieldPSItemList}
I tried the
but the PSReformList embedded data did not display anything in my survey question.
Qualtrics.SurveyEngine.addOnload(function()
{
var pipedText = "${e://Field/PSItemList}";
pipedList = pipedText.replace(/,/g, '
');
Qualtrics.SurveyEngine.setEmbeddedData("PSReformList",pipedList);
});
I would be willing to try the
tag but then does that mean I don't need to do the replace?
https://community.qualtrics.com/XMcommunity/discussion/comment/45053#Comment_45053A couple of things:
- You would still need the \\n if you use
- What question is this script attached to? You can't set and pipe an embedded data field on the same page. Piped values are resolved on the server before the page gets sent to the browser. If this is on the same page, you need to do the 'piping' with JS. See below.
In question html:
JS:
Qualtrics.SurveyEngine.addOnload(function() {
var pipedText = "${e://Field/PSItemList}";
var pipedList = pipedText.replace(/,/g, '
');
jQuery("#"+this.questionId+" .psItemList").html(pipedList);
});
I was trying to include the Javascript on the same page -- I so rarely do this I forgot about that requirement. It would not be easy to do this before that page, I'd have to insert a "fake" page then just to allow this. I reached out to the customer and he is okay with blank spaces in the display so I just have display logic for each item 6-20 to only display if they are populated. It isn't as "clean" as I would like it but this is much more Javascript code than I have experience with -- I don't feel this is worth all the testing. I appreciate all your replies in helping me try to get this working!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.