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 5 months ago #91796

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

Answer options based on previous question 8 months 1 week 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 8 months 6 days ago #128562

  • tpartner
  • tpartner's Avatar
  • Online
  • LimeSurvey Team
  • Posts: 6112
  • Thank you received: 1356
  • Karma: 532
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 8 months 6 days ago #128563

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
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 developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.

Answer options based on previous question 8 months 6 days 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 8 months 6 days 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 8 months 6 days ago #128572

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9254
  • Thank you received: 1319
  • Karma: 382
Hi, Tnoy solution was perfect :) and it work. Just to show alternatives :)
Assistance on LimeSurvey forum and LimeSurvey core developpement are on my free time (Say thanks ?).
A bug not reported is a bug not corrected. | Please, read the documentation | La doc en français à besoin de vous
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.411 seconds
Imprint                   Data Protection Statement                  Revocation information and revocation form