Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Limiting question count in group

More
11 years 4 months ago #87525 by niels
Limiting question count in group was created by niels
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 topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 4 months ago #87585 by tpartner
Replied by tpartner on topic Limiting question count in group
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.
Code:
<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 topic has been locked.
More
11 years 4 months ago #87591 by niels
Replied by niels on topic Aw: Re: Limiting question count in group
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 topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 4 months ago #87593 by tpartner
Replied by tpartner on topic Aw: Re: Limiting question count in group
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 topic has been locked.
More
11 years 4 months ago #87595 by niels
Okay, thank u!
The topic has been locked.
More
11 years 1 month ago #91816 by bwoo5
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 topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 month ago #91823 by tpartner
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 topic has been locked.
More
11 years 1 month ago #91828 by bwoo5
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 topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
11 years 1 month ago #91850 by tpartner
Replied by tpartner on topic Limiting question count in group
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.
Code:
<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 topic has been locked.
More
11 years 1 month ago #91857 by bwoo5
Replied by bwoo5 on topic Limiting question count in group
Thanks tpartner, works perfect and you're answers are always quick and efficient. Much appreciated.

Thanks again,
Bryon
The topic has been locked.
More
11 years 1 month ago #92609 by bwoo5
Replied by bwoo5 on topic Limiting question count in group
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 topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose