Answer options based on previous question

More
1 year 7 months ago #128567 by mmsurveys
mmsurveys replied the topic: Answer options based on previous question
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!

Please Log in to join the conversation.

More
1 year 7 months ago #128572 by DenisChenu
DenisChenu replied the topic: Answer options based on previous question
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 (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .

Please Log in to join the conversation.

More
4 months 3 weeks ago #147949 by Sabrina2017
Sabrina2017 replied the topic: Answer options based on previous question
Hi,

I tried this solution with Version 2.06 it work perfect, but not work on Version 2.57.1+161205, please how i need to change ?
<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>
Thanks

Please Log in to join the conversation.

More
4 months 3 weeks ago #147959 by tpartner
tpartner replied the topic: Answer options based on previous question
This will work in 2.5x:

<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
		$('.answer-item', thisQuestion).hide();
 
		// Now show the appropriate ones
		$(teacherLists[q1Ans].split(',')).each(function(i){
			$('input.radio[id$="'+{QID}+this+'"]').closest('.answer-item').show();
		});
 
		// Uncheck all hidden radios (in case page has been seen before)
		$('.answer-item:hidden input.radio', thisQuestion).prop('checked', false);
	});
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...1-30.lss
File Size:16 KB

Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: Sabrina2017

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now