Check out the LimeSurvey source code on GitHub!

Show multiple choice answers in different lines

5 years 8 months ago #61241 by Nodens

I have a multiple choice question with different anwers, for example:
[X] Answer 1
[ ] Answer 2
[X] Answer 3
[X] Answer 4

Using {INSERTANS} to show all the answers, the result is something like this:
Answer 1, Answer 3 & Answer 4

Is it possible to show these answers in separated lines, just like this:
Answer 1
Answer 3
Answer 4

Thank you very much!

Please Log in to join the conversation.

5 years 8 months ago - 5 years 8 months ago #61317 by tpartner
You could place the {INSERTANS} in a span and then use JavaScript to grab the contents of the span, get rid of the commas and ampersand and insert line breaks.

1) Place the {INSERTANS} tag in a span with a unique class. So the source would look something like:
<span class="prevAnswers">{INSERTANS:11111X22X33}</span>

2) Set up your survey to use JavaScript and place the following script in the source of the question:
<script type="text/javascript" charset="utf-8">
	$(document).ready(function() {
		var prevAnswers = $('.prevAnswers').text();
		prevAnswers = prevAnswers.replace(/ & /, '<br />');  
		prevAnswers = prevAnswers.replace(/, /, '<br />');

Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 5 years 8 months ago by tpartner.

Please Log in to join the conversation.

Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form