Condition based on number of possible answers

More
6 years 7 months ago - 6 years 7 months ago #57544 by AndrejL
AndrejL created the topic: Condition based on number of possible answers
Hi!

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
Last Edit: 6 years 7 months ago by AndrejL.

Please Log in to join the conversation.

More
6 years 7 months ago - 6 years 7 months ago #57545 by tpartner
tpartner replied the topic: Condition based on number of possible answers
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.

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last Edit: 6 years 7 months ago by tpartner.

Please Log in to join the conversation.

More
6 years 7 months ago #57546 by AndrejL
AndrejL replied the topic: Condition based on number of possible answers
I can store Q1 and Q2 in different groups but in general survey will be conducted in question-by-question mode.

This problem is just part of a much bigger survey and I can't change display format for hole survey.

Please Log in to join the conversation.

More
6 years 7 months ago #57547 by tpartner
tpartner replied the topic: Condition based on number of possible answers
Well, that makes it considerably more difficult because you can't use a hidden question to tally the number of checked boxes.

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.

Please Log in to join the conversation.

More
6 years 7 months ago #57557 by DenisChenu
DenisChenu replied the topic: Condition based on number of possible answers
tpartner , 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 ?

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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
6 years 7 months ago #57562 by tpartner
tpartner replied the topic: Condition based on number of possible answers

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 ?

Duh! Yeah, good idea! I couldn't see the tree because of the forest. :laugh:

Gimme a sec.

Cheers,
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.

More
6 years 7 months ago #57566 by tpartner
tpartner replied the topic: Condition based on number of possible answers
Oh wait...that would make it impossible to go back in the survey.

Cheers,
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.

More
6 years 7 months ago #57567 by AndrejL
AndrejL replied the topic: Condition based on number of possible answers
I have to check with higher authority :dry:

But that could be a problem.

If this was not an issue is it doable?

Andrej

Please Log in to join the conversation.

More
6 years 7 months ago - 6 years 7 months ago #57570 by tpartner
tpartner replied the topic: Condition based on number of possible answers
Almost anything is doable ;) We'll just have to revert to my idea of using a cookie.

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.
Last Edit: 6 years 7 months ago by tpartner.

Please Log in to join the conversation.

More
6 years 6 months ago #58820 by harshagile
harshagile replied the topic: Condition based on number of possible answers
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 Log in to join the conversation.

More
6 years 6 months ago #58822 by DenisChenu
DenisChenu replied the topic: Condition based on number of possible answers

harshagile 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.

www.limesurvey.org/en/forum/development/...of-lime-survey#58815

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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
1 year 8 months ago #130705 by mafo
mafo replied the topic: Condition based on number of possible answers

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?

Please Log in to join the conversation.

More
1 year 8 months ago #130715 by first
first replied the topic: Condition based on number of possible answers
Use EM. Search for count function here

Survey Designer and Programmer
The following user(s) said Thank You: mafo

Please Log in to join the conversation.

More
1 year 8 months ago #130716 by mafo
mafo replied the topic: Condition based on number of possible answers
Thanks! Got it:
{count(that.QQ)}

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now