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

TOPIC: Condition based on number of possible answers

Condition based on number of possible answers 3 years 8 months ago #57544

  • AndrejL
  • AndrejL's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 35
  • Karma: 1
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: 3 years 8 months ago by AndrejL.
The administrator has disabled public write access.

Re: Condition based on number of possible answers 3 years 8 months ago #57545

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4297
  • Thank you received: 810
  • Karma: 373
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 8 months ago by tpartner.
The administrator has disabled public write access.

Re: Condition based on number of possible answers 3 years 8 months ago #57546

  • AndrejL
  • AndrejL's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 35
  • Karma: 1
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.
The administrator has disabled public write access.

Re: Condition based on number of possible answers 3 years 8 months ago #57547

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4297
  • Thank you received: 810
  • Karma: 373
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.

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: Condition based on number of possible answers 3 years 8 months ago #57557

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6472
  • Thank you received: 854
  • Karma: 254
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 :)
The administrator has disabled public write access.

Re: Condition based on number of possible answers 3 years 8 months ago #57562

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4297
  • Thank you received: 810
  • Karma: 373
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.

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: Condition based on number of possible answers 3 years 8 months ago #57566

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4297
  • Thank you received: 810
  • Karma: 373
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.

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: Condition based on number of possible answers 3 years 8 months ago #57567

  • AndrejL
  • AndrejL's Avatar
  • OFFLINE
  • Bronze Donor
  • Posts: 35
  • Karma: 1
I have to check with higher authority :dry:

But that could be a problem.

If this was not an issue is it doable?

Andrej
The administrator has disabled public write access.

Re: Condition based on number of possible answers 3 years 8 months ago #57570

  • tpartner
  • tpartner's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 4297
  • Thank you received: 810
  • Karma: 373
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.

LimeSurvey is open-source and run entirely by volunteers so please consider donating to support the project.
Last Edit: 3 years 8 months ago by tpartner.
The administrator has disabled public write access.

Re: Condition based on number of possible answers 3 years 7 months ago #58820

  • harshagile
  • harshagile's Avatar
  • OFFLINE
  • Fresh Lemon
  • Posts: 18
  • Karma: 0
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.
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.143 seconds
Donation Image