Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: Limiting question count in group

Limiting question count in group 1 year 11 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.

Re: Limiting question count in group 1 year 11 months ago #87585

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4256
  • Thank you received: 801
  • Karma: 367
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Aw: Re: Limiting question count in group 1 year 11 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.

Re: Aw: Re: Limiting question count in group 1 year 11 months ago #87593

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4256
  • Thank you received: 801
  • Karma: 367
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Aw: Re: Aw: Re: Limiting question count in group 1 year 11 months ago #87595

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

Re: Aw: Re: Aw: Re: Limiting question count in group 1 year 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.

Re: Aw: Re: Aw: Re: Limiting question count in group 1 year 8 months ago #91823

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4256
  • Thank you received: 801
  • Karma: 367
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Aw: Re: Aw: Re: Limiting question count in group 1 year 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.

Re: Limiting question count in group 1 year 8 months ago #91850

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4256
  • Thank you received: 801
  • Karma: 367
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
The administrator has disabled public write access.

Re: Limiting question count in group 1 year 8 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.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.132 seconds
Donation Image