- Posts: 11
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Condition based on number of possible answers
- AndrejL
- Topic Author
- Offline
- New Member
I'm using array filters in my survey and I encounter a little problem.
It's possible that respondent answers survey in such way that he gets to a question that has no displayed answers.
Here is a simple example: test survey
If answer was checked in Q1 it doesn't display in Q2. So if you checked all 5 answer, second question is empty.
Of course in this case I could use filter if Q1<>1 or Q1<>"... but my case can't be solved this way.
Is there any workaround or filter that prevents question from displaying if number of possible answers is less then n.
Thank you,
Andrej
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10109
- Thank you received: 3595
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- AndrejL
- Topic Author
- Offline
- New Member
- Posts: 11
- Thank you received: 0
This problem is just part of a much bigger survey and I can't change display format for hole survey.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10109
- Thank you received: 3595
I think the only solution would be to use a cookie. I'll need to give it some thought and get back to you.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13648
- Thank you received: 2491
If this number is <1 then click the next button ?
If you don't have time, i can have a look , but only thursday
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10109
- Thank you received: 3595
Duh! Yeah, good idea! I couldn't see the tree because of the forest. :laugh:what do you think of a javascript in the question to test the number of line visible.
If this number is <1 then click the next button ?
Gimme a sec.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10109
- Thank you received: 3595
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- AndrejL
- Topic Author
- Offline
- New Member
- Posts: 11
- Thank you received: 0
But that could be a problem.
If this was not an issue is it doable?
Andrej
- tpartner
- Offline
- LimeSurvey Community Team
- Posts: 10109
- Thank you received: 3595
1) Set up the array filter exclusion between Q1 (the checkbox question) and Q2 (the radio question).
2) Add the following to the end of your template.js file. It is a little script to allow the recovery of cookies.
// a function to get the value of a cookie by name function getCookie ( cookieName ) { var results = document.cookie.match ( '(^|;) ?' + cookieName + '=([^;]*)(;|$)' ); if ( results ) { return ( unescape ( results[2] ) ); } else { return null; } }
3) Add the following to the source of Q1. Replace "3" in line 24 with the minimum number of options you would like to display in Q2. The script interrupts the next/submit function, does some math and if less than the minimum number of options are to be shown sets a cookie with a value of 1.
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { function minShown(minAllowed) { // Interrupt next/submit function $('form#limesurvey').submit(function(){ var visible = $('.multiple-opt input.checkbox').length - $('.multiple-opt input.checkbox:checked').length; // If less than the minimum, clear the question and move on if(visible < minAllowed) { document.cookie = 'lsSkipQ = 1'; } else { document.cookie = 'lsSkipQ = 0'; } // Carry on with submit return true; }); } minShown(3); }); </script>
4) Add the following to the source of Q2. The script retrieves the cookie and if the value is 1, unchecks all radio options and moves to the next question.
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Retrieve the cookie var skip = getCookie ('lsSkipQ'); // If we're supposed to skip, uncheck all options and move on if(skip > 0) { $('.list-radio').hide(); $('.list-radio input,radio').attr('checked', false); document.limesurvey.move.value = 'movenext'; document.limesurvey.submit(); } }); </script>
5) Add the following to the source of Q3 (the next question after the skip). The script retrieves the cookie and if the value is 1, adjusts the "Previous" buttons action to skip over the Q2 and go directly back to Q1.
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Retrieve the cookie var skip = getCookie ('lsSkipQ'); // Skip previous question if(skip > 0) { $('#moveprevbtn').mousedown(function () { $('#thisstep').val($('#thisstep').val() - 1); }); } }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
- harshagile
- Offline
- New Member
- Posts: 1
- Thank you received: 0
Do you have any idea about the limesurvey database.
I have just integrate limesurvey with my database.
But i didn't get table where all the answer stored.
I need to fetch all the response come for perticular survey
So if you have any idea abt that table name then please inform me.
- DenisChenu
- Offline
- LimeSurvey Community Team
- Posts: 13648
- Thank you received: 2491
www.limesurvey.org/en/forum/development/...of-lime-survey#58815harshagile wrote: Hi
Do you have any idea about the limesurvey database.
I have just integrate limesurvey with my database.
But i didn't get table where all the answer stored.
I need to fetch all the response come for perticular survey
So if you have any idea abt that table name then please inform me.
Please : don't crosspost
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
- mafo
- Offline
- Junior Member
- Posts: 25
- Thank you received: 0
tpartner wrote: It appears that you are using question-by-question mode. Is it possible to separate the questions into different groups and use group-by-group mode? If so, we would be able to use a hidden question to store the number of checked boxes in Q1 and then apply a condition to Q2.
How exactly can the number of checked boxes be stored in a hidden question?