Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:

TOPIC: Limiting question count in group

Limiting question count in group 3 years 10 months ago #87525

  • niels
  • niels's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
Hi there,

we set up a question group with potentially 10 questions. Each question depends on a different relevance equation and may or may not be shown. We're looking for a possibility to limit the number of asked questions in this group. In other words, if two of the questions have been shown, we want to step forward to the next group.
The questions are non mandatory text inputs, so we can't use the answers as a counter.
I tried different ways but none worked.
Is it possible to implement a javascript counter and access it from the Expression Manager?
Do you have any ideas?
The administrator has disabled public write access.

Limiting question count in group 3 years 10 months ago #87585

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6317
  • Thank you received: 1407
  • Karma: 546
I don't believe you can do that with Expression Manager but you can with JavaScript.

1) Set the questions in the 10-question group to display in a random order.

2) Add the following to the source of one of the questions in that group. The script hides all but the first two questions that are shown by relevance. Adjust "maxShown" to change the number of questions shown.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
		var maxShown = 2;
		$('.question-wrapper:visible').each(function(i){
			if(i > (maxShown - 1)) {
				$(this).hide();
			}
		});
	});
 
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Aw: Re: Limiting question count in group 3 years 10 months ago #87591

  • niels
  • niels's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
Hi tpartner,

thanks for your answer.

I'm sorry I didn't explain directly but the order of those questions needs to be fixed because they are prioritised.
And idealisticly we want the survey to be run question by question.

Any ideas?

Thx in advance, cheers // nielo
The administrator has disabled public write access.

Aw: Re: Limiting question count in group 3 years 10 months ago #87593

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6317
  • Thank you received: 1407
  • Karma: 546
The solution above will work for fixed positions if run in "group by group" mode.

There is no easy JavaScript solution for "question by question" mode.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Limiting question count in group 3 years 10 months ago #87595

  • niels
  • niels's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 6
  • Karma: 0
Okay, thank u!
The administrator has disabled public write access.

Aw: Re: Aw: Re: Limiting question count in group 3 years 8 months ago #91816

  • bwoo5
  • bwoo5's Avatar
  • Offline
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
Hi Tpartner,

With the script you provided above, is there any code that I could add to it to make it so that one of the questions in the group always showed and the rest of them were random? I have 5 questions in a group and need for 1 of them to always show along with 1 other than is random between the 4.

Thanks!
The administrator has disabled public write access.

Aw: Re: Aw: Re: Limiting question count in group 3 years 8 months ago #91823

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6317
  • Thank you received: 1407
  • Karma: 546
bwoo5, the code above will work for your situation as-is.

Place the "always shown" question first in the group and then give all remaining "random" questions a "Randomization group name".

The code hides all but the first two questions on the page so will show the "always shown" question and the first of the remaining questions.
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Limiting question count in group 3 years 8 months ago #91828

  • bwoo5
  • bwoo5's Avatar
  • Offline
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
Hi tpartner,

I forgot to mention one criteria, sorry! Here are the criteria
1. 5 locations
2. 1 location is always to be shown
3. the other 4 locations are randomly shown
4. the 1 location that is always to be shown, has to randomly appear 1st or 2nd of the 2 total questions that show.
I tried putting 2 of the random questions before the one that shows all the time and 2 after but can't get that to work. Any ideas?
The administrator has disabled public write access.

Limiting question count in group 3 years 7 months ago #91850

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6317
  • Thank you received: 1407
  • Karma: 546
Okay, follow the instructions above and use this code. After showing the two questions, it will randomize their order.

I've also tweaked the code a bit to suit other templates.
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		// Hide all but the first two questions
		var maxShown = 2;
		$('div[id^="question"]:visible').each(function(i){
			if(i > (maxShown - 1)) {
				$(this).hide().addClass('hiddenQuestion');
			}
			else {
				$(this).addClass('shownQuestion');
			}
		});
 
		// Random display of the 2 shown questions
		var rand = Math.floor(Math.random()*2 + 1);
		if(rand == 1) {
			var parent = $('div[id^="question"]:eq(0)').parent();
			$(parent).append($('.shownQuestion:eq(0)'));
		}
	});
</script>
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Limiting question count in group 3 years 7 months ago #91857

  • bwoo5
  • bwoo5's Avatar
  • Offline
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
Thanks tpartner, works perfect and you're answers are always quick and efficient. Much appreciated.

Thanks again,
Bryon
The administrator has disabled public write access.

Limiting question count in group 3 years 7 months ago #92609

  • bwoo5
  • bwoo5's Avatar
  • Offline
  • Expert Lime
  • Posts: 80
  • Thank you received: 4
  • Karma: 0
Hi Tpartner, (willing to donate for a solution to this)!! Thanks!!

Have a new question for you about this topic to see if it is possible. Here is the situation.
1. 5 locations that each have their own array of statements to rate 1-5.
2. Only 2 of the locations are shown to each person.
3. 1 of the other locations is always shown, out of the other 4 they are randomly shown to get an even distribution of responses.
*ok here is where things change from previous code
4. The 2 locations shown have to be in different groups ( 1 array per page, no other questions on the page)
5. The location that is always shown, need to randomize between the 1st and 2nd page.
6. If possible, I have a question earlier in the survey that asks if they have visited the location in the last year.. I need for the 2nd location that is randomly selected to also have a conditional based on that question.
So the requirements are as follows
1. The first location will always show up, either on the first page or second.
2. The second location will show up on the page that the first location isn't on
3. the second location has to meet the conditional of being visited in the last year (from a previous array question where i have all the locations listed and select last visit time periods) *I see the issue being that if the randomizer chooses a location that hasn't been visited in the last year, it will not show anything for the 2nd location instead of moving onto another location
The administrator has disabled public write access.
Time to create page: 0.277 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form