Welcome to the LimeSurvey Community Forum

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

Hiding responses on a mult choice question based on a single choice

  • vadindot
  • vadindot's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 3 weeks ago #117697 by vadindot
I recently switched over to 2.0.5, and an old questionnaire of mine no longer works.

I have a question (q1) that has a list of 36 locations.
I have a question (q7) that has 26 items, which vary because each of the different locations may have a separate subset of them.

What I used to use (thanks to tpartner) is a hidden question underneath q1 which would check off the items that each location might have, and then that would filter q7. Unfortunately, it is not working. Here is the javascript that would go into the question, I was wondering if anyone can help me update it.
Code:
 <script type="text/javascript" charset="utf-8">
 
  $(document).ready(function(){
                //THIS IS THE AT-CENTER VERSION
    // The question IDs
    var q1 = 1;
    var qHidden = 40;
 
    // Hide the hidden question
    $('#question'+qHidden+'').hide();
 
    // Assign classes to the inputs
    $('#question'+q1+' input.radio').each(function(i) {
      $(this).addClass('q1Row'+(i+1)+'');
    });
    $('#question'+qHidden+' input.checkbox').each(function(i) {
      $(this).addClass('qHiddenRow'+(i+1)+'');
    });
 
    // Interrupt the Next/Submit function
    $('form#limesurvey').submit(function(){
 
      // Reset the hidden question
      $('#question'+qHidden+' input.checkbox').attr('checked', false);
 
      // If q1 row 1 is checked we do this
      if($('.q1Row1').attr('checked') == true) {
        $('.qHiddenRow1').attr('checked', true);
        $('.qHiddenRow2').attr('checked', true);
        $('.qHiddenRow3').attr('checked', false);
        $('.qHiddenRow4').attr('checked', true);
      }
      if($('.q1Row2').attr('checked') == true) {
        $('.qHiddenRow1').attr('checked', false);
        $('.qHiddenRow2').attr('checked', true);
        $('.qHiddenRow3').attr('checked', true);
        $('.qHiddenRow4').attr('checked', true);
      }
 
      // Carry on with submit
      return true;
    });    
 
  })
 
</script>
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 3 weeks ago #117708 by tpartner
Replace all instances of:
Code:
.attr('checked'

With:
Code:
.prop('checked'

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: vadindot
The topic has been locked.
  • vadindot
  • vadindot's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
9 years 2 weeks ago #117784 by vadindot
That would be it

Thanks Tony!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose