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

rarcegararcega CanadaCommunity Member Qubie ✭

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

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.

Best Answer

  • rondevrondev Community Member - Trial User Wizard ✭✭✭✭✭
    Accepted Answer

    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') );
    

Answers

Sign In to Comment