I am piping answers to a subsequent question, but when two of the options are selected and displayed using piped text it uses a comma rather than 'and' (see pic below).
How can I replace the comma with 'and', but only when two answers were selected (e.g., i don't want 'and' displayed when only one answer was selected). Does anyone have a solution to this please - i'm new to Qualtrics so might have missed an obvious solution.
In the question HTML pipe the answers into a span. Something like this:
${...}
Then use JS to convert the commas to and.
Qualtrics.SurveyEngine.addOnReady(function () {
let new_text = this.questionContainer
.querySelector("#my_answers")
.innerText.replaceAll(",", " and");
this.questionContainer.querySelector("#my_answers").innerText = new_text;
});
Thank you!
https://www.qualtrics.com/community/discussion/comment/35798#Comment_35798Hi again,
Thank you very much again for your help! This worked perfectly, but now I am wondering how I can ensure this is translated when the survey is completed in another language. For example, when translated from English, the two answers are translated, but not the "and" which remains in English? Do you know how i would ensure the "and" would be translated?
Thank you!
Qualtrics.SurveyEngine.addOnReady(function () {
let lang = "${e://Field/Q_Language}",
replacement;
switch (lang) {
case "EN-GB":
replacement = "and";
break;
case "FR":
replacement = "et";
break;
case "AR":
replacement = "و";
break;
default:
replacement = "&";
}
let new_text = this.questionContainer
.querySelector("#my_answers")
.innerText.replaceAll(",", " " + replacement);
this.questionContainer.querySelector("#my_answers").innerText = new_text;
});
If you'd like to customize it for each language, you can use the code above. Add any other languages you want using the case format as above, ensure that it's before
default. The
defaultcondition is a fallback when none of the other cases are applicable.
Alternatively, you could just use
&for all, by changing
" and"in the earlier code to
" &".
Thank you very much ahmedA !!
Leave a Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.