Welcome, Guest
Username: Password: Remember me

TOPIC: Show multiple choice answers in different lines

Show multiple choice answers in different lines 3 years 1 month ago #61241

  • Nodens
  • Nodens's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 4
  • Karma: 0
Hello!

I have a multiple choice question with different anwers, for example:
Question:
[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!
The administrator has disabled public write access.

Re: Show multiple choice answers in different lines 3 years 1 month ago #61317

  • tpartner
  • tpartner's Avatar
  • NOW ONLINE
  • LimeSurvey Team
  • Posts: 4049
  • Thank you received: 739
  • Karma: 341
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 />');
 
		$('.prevAnswers').html(prevAnswers);
 
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 1 month ago by tpartner.
The administrator has disabled public write access.
Moderators: ITEd
Time to create page: 0.151 seconds
Donation Image