Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Disabled answer in a question base on selected answer in previous question

  • jajas
  • jajas's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
9 years 3 months ago #115735 by jajas
Dear LS Team,

How to disabled answer in a question base on selected answer in previous question.
bellow is the figure:

C1. Do you know the Ferrari Team [Single Answer]
[1] Yes
[2] No

C2. Do you know the Ferrari Team to be champion [Single Answer]
[1] Yes
[2] No

C3. How deep you know about Ferrari[Single Answer]
[1] I don't know
[2] I don't know att all
[3] I know it very much
[4] I'm very Friendly with Ferrari

i need to disable the answer 3 & 4 in Question C3 if in question C1 and C2 selected "NO" answer.
Need your help to solve it

Regards,

Jajas
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 months ago - 9 years 3 months ago #115766 by tpartner
Currently there is no built-in filtering for answers. You can use JavaScript, a hidden multiple-choice question and array filtering to mimic it...or just use two separate questions.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 3 months ago by tpartner.
The topic has been locked.
  • jajas
  • jajas's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
9 years 3 months ago #115769 by jajas
Can you give me a sample, Please?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 months ago #115770 by tpartner
Searching the forum should yield some examples. Here is one for arrays that could be easily adapted for your needs - www.limesurvey.org/en/forum/can-i-do-thi...estion-result#112088


.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • jajas
  • jajas's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
9 years 3 months ago #115790 by jajas
I think it's different case. hmmm...
The topic has been locked.
More
9 years 2 months ago #115832 by Bigred01
Assuming your questions are on different pages and C3 is the only radio question on its page you could do something like...
Code:
$(document).ready(function() {
 
var prevAns =  "{C1.NAOK} "  === "2"  &&  "{C2.NAOK} "  === "2" ;
 
if(prevAns) {
     $(".radio:eq(2),.radio:eq(3)").attr("disabled",true);
}
});
The topic has been locked.
  • jajas
  • jajas's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
9 years 2 months ago #115833 by jajas
Hi Bigred,

Thanks for replay. in my case the question in same page.
could u give me a script sample for case in same page.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 2 months ago #115835 by tpartner

I think it's different case. hmmm...

Here is an example for your situation.

The following script is placed in the source of a hidden multiple-choice question that is inserted between C2 and C3. The script toggles the check-boxes in the hidden question depending on the state of C2 and C3. Array filter exclusion then handles the display of the last two answers in C3.

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    // Identify the elements
    var qHidden = $('#question{QID}');
    var qC1 = qHidden.prevAll('.list-radio:eq(1)');
    var qC2 = qHidden.prevAll('.list-radio:eq(0)');
    var inputs = $('input[type="radio"]', qC1).add('input[type="radio"]', qC2);
 
    // Hide the filter question
    qHidden.hide();
 
    // Listener on C1 and C2
    $(inputs).click(function(e) {
 
      // Toggle the checkboxes in the hidden question
      if ($('input.radio:last', qC1).is(':checked') || $('input.radio:last', qC2).is(':checked')) {
        $('input.checkbox', qHidden).prop('checked', true);
        $('li.question-item input[type="hidden"]', qHidden).val('Y');
      }
      else {
        $('input.checkbox', qHidden).prop('checked', false);
        $('li.question-item input[type="hidden"]', qHidden).val('');
      }  
 
      // Fire the array filter
      $('input.checkbox', qHidden).each(function(i) {
        checkconditions($(this).attr('value'), $(this).attr('name'), $(this).attr('type'));
      });
    });
 
    });
</script>





Here's a sample survey:

File Attachment:

File Name: limesurvey...4176.lss
File Size:19 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: jajas
The topic has been locked.
  • Mazi
  • Mazi's Avatar
  • Offline
  • Official LimeSurvey Partner
  • Official LimeSurvey Partner
More
9 years 2 months ago #115858 by Mazi
Great solution, Tony!

Can you add that to the wiki as a Christmas present :-)

Best regards/Beste Grüße,
Dr. Marcel Minke
Need Help? We offer professional Limesurvey support: survey-consulting.com
Contact: marcel.minke(at)survey-consulting.com
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose