Check out the LimeSurvey source code on GitHub!

Limit number of questions in survey

3 years 4 months ago - 3 years 4 months ago #99709 by Breut
Hi all,

I'm using 2.00+ build 130708

I have 6 groups with 40+ questions in each group.
I would like to limit the number of questions shown from each group to the person taking the survey, e.g. show 10 random questions from group 1, 15 random questions from group 2 etc.

Please advise on how to proceed.

Thanks in advance,
Last Edit: 3 years 4 months ago by Breut. Reason: excess text

Please Log in to join the conversation.

3 years 4 months ago #99713 by tpartner
Assuming you are using "group-by-group" mode, you can randomize the question order in each group and then use JavaScript to hide all but the first n questions.

Details of the script may vary by template but would look something like this:

<script type="text/javascript" charset="utf-8">	
		var questionsShown = 10;
		$('div[id^="question"]').each(function(i) {
			if(i >= questionsShown) {

Tony Partner

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

Please Log in to join the conversation.

3 years 4 months ago #99718 by Breut
Thanks for your answer, however I forgot to mention I need to use question by question mode.

Anyway I see where you are getting at - would it be possible with the question by question mode and if yes, where do I implement the Javascript code?


Please Log in to join the conversation.

3 years 4 months ago #99747 by Breut

@Tony, the reason why I need to use question by question mode is because I need total randomisation of the questions. In another thread I posted the issue of totally randomizing between groups but as this wasn't answered I needed to revert to using the question by question mode.

This being said, I found an almost working solution using the Expression Manager but it's not that elegant so comments and improvements welcome.

Assume I want 10 questions of N to be displayed
  • I defined a hidden question before all regular questions with code numQuestions and numerical value = 0
  • I then added 1 to that numerical value each time a question is shown
  • I then added the relevance equation numQuestions<=10

This way of working does the trick, however:
  • In each "regular" question I now have a numerical value showing up as adding 1 to the numQuestions variable shows that new value. Question is can I hide this value?
  • When the relevance equation is false (so numQuestions is > 10) an "empty" question is shown while taking the survey that needs a click on the "next" button in order to move on. This is really awkward. Why is this question shown as the relevance equation is false? How can I get rid of it?

Thanks for advising on whether this is a good way to go about this and how to solve these issues.

PS: To be even more specific, there are multiple numQuestions variables running through each other as they mimick the 'groups' I mentioned before (so numQuestionsG1, numQuestionsG2, etc). Again, this works fine but shows an "empty" question per group the moment the relevance equation goes over the threshold of 10 shown questions.

Please Log in to join the conversation.

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