Piping selected choices and adding 'and' before the last choice

in Custom Code
Piping selected choices and adding 'and' before the last choice
in Custom Code
I have a question with a set of retailers. If I selected Walmart, Costco and Amazon, how can I pipe them to a question with the 'and' added to it?
Walmart, Costco and Amazon
If I use SelectedChoices, it separates everything by a comma.
Tagged:
0
Best Answer
-
rondev Community Member - Trial User Wizard ✭✭✭✭✭
In the question text html view wrap the pipe text with span tag and give a class attribute to it as shown below:
<span class="pipetext">${q://QID509/ChoiceGroup/SelectedChoices}</span>
In the javascript of this question where we are displaying the pipe text, paste the below code:
jQuery(".pipetext").text(jQuery(".pipetext").text().replace(/,([^,]*)$/, " and" + '$1') );
0
Sign In to Comment
Answers
Thanks!