- Posts: 14
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Answer options based on previous question
- stuttgarter
- Topic Author
- Offline
- New Member
Less
More
11 years 3 months ago #91796
by stuttgarter
Replied by stuttgarter on topic Answer options based on previous question
Thanks a lot Tony .
The topic has been locked.
- mmsurveys
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
8 years 5 months ago #128545
by mmsurveys
Replied by mmsurveys on topic Answer options based on previous question
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!
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 topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10116
- Thank you received: 3597
8 years 5 months ago #128562
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Answer options based on previous question
Assuming both questions are single-choice radios, remove the script from Q1 and add something like this to Q2:
Sample survey attached:
Code:
<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:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13684
- Thank you received: 2497
8 years 5 months ago #128563
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on topic Answer options based on previous question
Hi,
I use another method, using an "multiple choice" and check it acording to selection : demonstration.sondages.pro/676785#
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 , plugin development .
I don't answer to private message.
The topic has been locked.
- mmsurveys
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
8 years 5 months ago #128566
by mmsurveys
Replied by mmsurveys on topic Answer options based on previous question
Thank you very much Tony!!! This should do the job!
The topic has been locked.
- mmsurveys
- Offline
- New Member
Less
More
- Posts: 3
- Thank you received: 0
8 years 5 months ago #128567
by mmsurveys
Replied by mmsurveys on 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!
Tonys version should work. If not, I'll come again and try the translator or just ask
Many thanks to you!
The topic has been locked.
- DenisChenu
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 13684
- Thank you received: 2497
8 years 5 months ago #128572
by DenisChenu
Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand , plugin development .
I don't answer to private message.
Replied by DenisChenu on 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 , plugin development .
I don't answer to private message.
The topic has been locked.
- Sabrina2017
- Offline
- New Member
Less
More
- Posts: 7
- Thank you received: 0
7 years 3 months ago #147949
by Sabrina2017
Replied by Sabrina2017 on 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
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
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10116
- Thank you received: 3597
7 years 3 months ago #147959
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Answer options based on previous question
This will work in 2.5x:
Sample survey attached:
Code:
<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:
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
The topic has been locked.
- saifshaikh
- Offline
- Junior Member
Less
More
- Posts: 23
- Thank you received: 0
6 years 7 months ago #158678
by saifshaikh
Replied by saifshaikh on topic Answer options based on previous question
Hi Tony,
Can the above soloution work in ver 2.6 with both the question been on the same page.
Can the above soloution work in ver 2.6 with both the question been on the same page.
The topic has been locked.
- AdinaNica1
- Offline
- New Member
Less
More
- Posts: 13
- Thank you received: 0
6 years 6 months ago - 6 years 6 months ago #160316
by AdinaNica1
Replied by AdinaNica1 on topic Answer options based on previous question
Hi!
I have a similar situation. I have tried to use the script that you shared and it didn't work (once you tick a certain answer in q1 it doesn't modify the options in Q2). I also tried to use your test survey, and it is the same result, no change. Is there anything else I should have done? Is this working only for certain versions?My version is 2.67.3+170728.
Many many thanks!
I have a similar situation. I have tried to use the script that you shared and it didn't work (once you tick a certain answer in q1 it doesn't modify the options in Q2). I also tried to use your test survey, and it is the same result, no change. Is there anything else I should have done? Is this working only for certain versions?My version is 2.67.3+170728.
Many many thanks!
Last edit: 6 years 6 months ago by AdinaNica1.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10116
- Thank you received: 3597
6 years 6 months ago #160345
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Answer options based on previous question
This script will work in 2.7.x:
Sample survey attached:
Code:
<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){ $('.answer-item[id$="'+{QID}+this+'"]').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:
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: AdinaNica1
The topic has been locked.