Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: Answer options based on previous question

Answer options based on previous question 3 years 10 months ago #91796

Thanks a lot Tony :) .
The administrator has disabled public write access.

Answer options based on previous question 1 year 3 weeks ago #128545

  • mmsurveys
  • mmsurveys's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
Hello, I have a another question based on this situation.
How do I do this if the questions are not on the same page? (So If I display the questions page per page).
Question 1 lets the user choose the course
Question 2 lets the user select the teacher which is possible for the selected course?

Can you please give me a shot example?!
Many thanks in advance!
The administrator has disabled public write access.

Answer options based on previous question 1 year 3 weeks ago #128562

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 6573
  • Thank you received: 1477
  • Karma: 579
Assuming both questions are single-choice radios, remove the script from Q1 and add something like this to Q2:

<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		// The Q2 options corresponding to the Q1 options		
		teacherLists = {
			C1 : 'T1,T3,T5',
			C2 : 'T1,T2,T3,T4',
			C3 : 'T2,T3,T4,T5',
			C4 : 'T1,T4,T6'
		};
 
		// Identify this question
		var thisQuestion = $('#question{QID}')
 
		// The checked option in Q1
		var q1Ans = '{Q1}';
 
		// Hide all of the teachers
		$('li[id^="javatbd"]', thisQuestion).hide();
 
		// Now show the appropriate ones
		$(teacherLists[q1Ans].split(',')).each(function(i){
			$('input.radio[id$="'+{QID}+this+'"]').closest('li').show();
		});
 
		// Uncheck all hidden radios (in case page has been seen before)
		$('li[id^="javatbd"]:hidden input.radio', thisQuestion).prop('checked', false);
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...2(1).lss
File Size:16 KB
Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The administrator has disabled public write access.

Answer options based on previous question 1 year 3 weeks ago #128563

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9586
  • Thank you received: 1375
  • Karma: 390
Hi,

I use another method, using an "multiple choice" and check it acording to selection : demonstration.sondages.pro/676785#
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (use private message).
The administrator has disabled public write access.

Answer options based on previous question 1 year 3 weeks ago #128566

  • mmsurveys
  • mmsurveys's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
Thank you very much Tony!!! This should do the job!
The administrator has disabled public write access.

Answer options based on previous question 1 year 3 weeks ago #128567

  • mmsurveys
  • mmsurveys's Avatar
  • Offline
  • Fresh Lemon
  • Posts: 3
  • Karma: 0
Hey Denis, thank you for the suggestion. unfortunately, I'm a bit confused due to my lack of speaking French :/
Tonys version should work. If not, I'll come again and try the translator or just ask ;)
Many thanks to you!
The administrator has disabled public write access.

Answer options based on previous question 1 year 3 weeks ago #128572

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9586
  • Thank you received: 1375
  • Karma: 390
Hi, Tnoy solution was perfect :) and it work. Just to show alternatives :)
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (use private message).
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.280 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form