Bienvenue, Invité
Nom d'utilisateur : Mot de passe : Se souvenir de moi
  • Page :
  • 1
  • 2

SUJET : Answer options based on previous question

Answer options based on previous question il y a 1 an 6 mois #91501

  • stuttgarter
  • Portrait de stuttgarter
  • Hors ligne
  • Fresh Lemon
  • Messages : 11
  • Karma: 0
Hello,
I have two set of attributes
1. Courses : C1, C2, C3, C4 etc.
2. Teachers: T1, T2, T3, T4, T5, T6

Now
Q1: Course
Q2: Teacher

If user Chooses C1, options in Q2 should be T1, T3, T5
If user Chooses C2, options in Q2 should be T1, T2, T3, T4
If user Chooses C3, options in Q2 should be T2, T3, T4, T5 and so on

Any Suggestions???
L'administrateur a désactivé l'accès en écriture pour le public.

Aw: Answer options based on previous question il y a 1 an 6 mois #91507

  • ResearchOnBlogs
  • Portrait de ResearchOnBlogs
  • Hors ligne
  • Gold Lime
  • Messages : 184
  • Remerciements reçus 16
  • Karma: 8
This should be possible with the Expression Manager and an array filter.

Cheers Kai

research on BLOGS - Professional LimeSurvey support
Consultant - Templates - Training - JQuery magic - Support - Coding - Survey creation and more..

Contact
Professional LimeSurvey support
Cette adresse e-mail est protégée contre les robots spammeurs. Vous devez activer le JavaScript pour la visualiser.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Answer options based on previous question il y a 1 an 6 mois #91524

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4071
  • Remerciements reçus 748
  • Karma: 341
I don't think array filter will work in this case because you would like to show several options in Q2 per Q1 option. Array filter is limited to identical answer codes in both questions.

You could do it with custom JavaScript but the details of that script would depend on your question types and the filtering criteria.
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.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Answer options based on previous question il y a 1 an 6 mois #91541

  • stuttgarter
  • Portrait de stuttgarter
  • Hors ligne
  • Fresh Lemon
  • Messages : 11
  • Karma: 0
Both question types are radio button.
Could you elaborate a bit more about java script possibility?
Currently i am doing it manually and Q1 & Q2 are all together more than 100 possible questions by using if condition and its making me mad.

Thanks in advance.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Answer options based on previous question il y a 1 an 6 mois #91625

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4071
  • Remerciements reçus 748
  • Karma: 341
Okay, here's a little script that if placed in the source of Q1, will filter Q2 per your example above.

Assumptions are:
- both questions are on the same page
- both are list-radios
- they use the answer codes defined above
- the script is placed in the source of the first question
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		// The Q2 options relevant to the Q1 options		
		teacherLists = {
			C1 : 'T1,T3,T5',
			C2 : 'T1,T2,T3,T4',
			C3 : 'T2,T3,T4,T5',
			C4 : 'T1,T4,T6',
		};
 
		// Identify the questions
		var q1ID = '{QID}';
		var q1 = $('#question'+q1ID+'');
		var q2 = $(q1).nextAll('.list-radio:eq(0)'); 
		var q2ID = $(q2).attr('id').split('question')[1];
 
		// Find the initially checked option in Q1 (if any)
		var q1Ans = '';
		if($('input.radio:checked', q1).length > 0) {
			q1Ans = $('input.radio:checked', q1).attr('value');
		}
 
		// Initially Hide/Show the appropriate teachers
		showTeachers(q1Ans);
 
		// Click events on Q1 radios
		$('input.radio', q1).click(function() {
			var value = $(this).attr('value');
			// Q1 has been changed
			if(value != q1Ans) {
				q1Ans = value;
				// Clear the Q2 answer
				$('input.radio', q2).attr('checked', false)
				// Show the appropriate teachers
				showTeachers(q1Ans);
			}
		});
 
		// A function to show the appropriate teachers
		function showTeachers(q1Ans) {
			// Hide all of the teachers
			$('li[id^="javatbd"]', q2).hide();
			// Now show the appropriate ones
			if(q1Ans != '') {
				$(teacherLists[q1Ans].split(',')).each(function(i){
					$('input.radio[id$="'+q2ID+this+'"]').closest('li').show();
				});
			}
		}
 
	});
</script>

Here's a demo survey:

Fichier attaché :

Nom du fichier : limesurvey_survey_361532.lss
Taille du ficher : 18 KB
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.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Answer options based on previous question il y a 1 an 6 mois #91627

  • stuttgarter
  • Portrait de stuttgarter
  • Hors ligne
  • Fresh Lemon
  • Messages : 11
  • Karma: 0
I appreciate your answer. Exactly the way i wanted.

Million thanks.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Answer options based on previous question il y a 1 an 6 mois #91730

  • stuttgarter
  • Portrait de stuttgarter
  • Hors ligne
  • Fresh Lemon
  • Messages : 11
  • Karma: 0
Your solution is working great.
I am trying to implement the same script for another question set with Q1(Radio) and Q2(Multiple Choice) but its not working. I have changed the code from radio to checkbox.

Any guidance would be much appreciated.

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){

// The Q2 options relevant to the Q1 options
teacherLists = {
C1 : 'T1,T3,T5',
C2 : 'T1,T2,T3,T4',
C3 : 'T2,T3,T4,T5',
C4 : 'T1,T4,T6',
};

// Identify the questions
var q1ID = '{QID}';
var q1 = $('#question'+q1ID+'');
var q2 = $(q1).nextAll('.list-radio:eq(0)');
var q2ID = $(q2).attr('id').split('question')[1];

// Find the initially checked option in Q1 (if any)
var q1Ans = '';
if($('input.radio:checked', q1).length > 0) {
q1Ans = $('input.radio:checked', q1).attr('value');
}

// Initially Hide/Show the appropriate teachers
showTeachers(q1Ans);

// Click events on Q1 radios
$('input.radio', q1).click(function() {
var value = $(this).attr('value');
// Q1 has been changed
if(value != q1Ans) {
q1Ans = value;
// Clear the Q2 answer
$('input.checkbox', q2).attr('checked', false)
// Show the appropriate teachers
showTeachers(q1Ans);
}
});

// A function to show the appropriate teachers
function showTeachers(q1Ans) {
// Hide all of the teachers
$('li[id^="javatbd"]', q2).hide();
// Now show the appropriate ones
if(q1Ans != '') {
$(teacherLists[q1Ans].split(',')).each(function(i){
$('input.checkbox[id$="'+q2ID+this+'"]').closest('li').show();
});
}
}

});
</script>
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Answer options based on previous question il y a 1 an 6 mois #91751

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4071
  • Remerciements reçus 748
  • Karma: 341
You missed one selector.

This:
var q2 = $(q1).nextAll('.list-radio:eq(0)');
Should be this:
var q2 = $(q1).nextAll('.multiple-opt:eq(0)');
<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		// The Q2 options relevant to the Q1 options		
		teacherLists = {
			C1 : 'T1,T3,T5',
			C2 : 'T1,T2,T3,T4',
			C3 : 'T2,T3,T4,T5',
			C4 : 'T1,T4,T6',
		};
 
		// Identify the questions
		var q1ID = '{QID}';
		var q1 = $('#question'+q1ID+'');
		var q2 = $(q1).nextAll('.multiple-opt:eq(0)'); 
		var q2ID = $(q2).attr('id').split('question')[1];
 
		// Find the initially checked option in Q1
		var q1Ans = '';
		if($('input.radio:checked', q1).length > 0) {
			q1Ans = $('input.radio:checked', q1).attr('value');
		}
 
		// Initially Hide/Show the appropriate teachers
		showTeachers(q1Ans);
 
		// Click events on Q1 radios
		$('input.radio', q1).click(function() {
			var value = $(this).attr('value');
			// Q1 has been changed
			if(value != q1Ans) {
				q1Ans = value;
				// Clear the Q2 answer
				$('input.checkbox', q2).attr('checked', false)
				// Show the appropriate teachers
				showTeachers(q1Ans);
			}
		});
 
		// A function to show the appropriate teachers
		function showTeachers(q1Ans) {
			// Hide all of the teachers
			$('li[id^="javatbd"]', q2).hide();
			// Now show the appropriate ones
			if(q1Ans != '') {
				$(teacherLists[q1Ans].split(',')).each(function(i){
					$('input.checkbox[id$="'+q2ID+this+'"]').closest('li').show();
				});
			}
		}
 
	});
</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.
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Answer options based on previous question il y a 1 an 6 mois #91774

  • stuttgarter
  • Portrait de stuttgarter
  • Hors ligne
  • Fresh Lemon
  • Messages : 11
  • Karma: 0
Thank you very much Tony.
just one more question:
Is there any list/reference of selector codes like multiple-opt, list.radio etc. based on lime survey question types?
L'administrateur a désactivé l'accès en écriture pour le public.

Re: Answer options based on previous question il y a 1 an 6 mois #91775

  • tpartner
  • Portrait de tpartner
  • Hors ligne
  • LimeSurvey Team
  • Messages : 4071
  • Remerciements reçus 748
  • Karma: 341
Yup - docs.limesurvey.org/The+template+editor&..._of_question_classes

Or you can explore the document with a tool like Firebug for Firefox:

Capture_2013-01-26.JPG
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.
L'administrateur a désactivé l'accès en écriture pour le public.
  • Page :
  • 1
  • 2
Modérateurs: ITEd
Temps de génération de la page : 0.175 secondes
Donation Image