Welcome to the LimeSurvey Community Forum

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

Hiding specific checkboxes in multiple choice question

More
8 years 11 months ago - 8 years 11 months ago #119673 by marba
Hi!

I have a multiple options question in which I'm using some options as a category title. For that, I used the sub-options workaround, made the category titles checked by definition, and then hide those checkboxes, as they are not clickable-options.
To hide them, I wrote this on the question code:
Code:
<script charset="utf-8" type="text/javascript">      
   $(document).ready(function() {  
 
        $( 'input.checkbox', 'li.question-item:eq(0)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(5)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(10)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(15)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(19)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(23)' ).css ({                     
              'display': 'none' 
});
        $( 'input.checkbox', 'li.question-item:eq(29)' ).css ({                     
              'display': 'none' 
});
 
 
});
</script>





It works perfectly, but what is happening is that a previous answer of multiple choice is being affected by this and some checkboxes disappear!






How can I make this code affect only this question and its subquestions?




Thanks!
Last edit: 8 years 11 months ago by DenisChenu. Reason: Usage of code
The topic has been locked.
  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #119685 by DenisChenu
You have to restrivt to THIS question:

$( 'input.checkbox', '#question{QID} li.question-item:eq(0)' ).css ({

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 following user(s) said Thank You: marba
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 11 months ago #119724 by tpartner
I don't think you need to use scope here. Simple selectors should work.

Code:
<script charset="utf-8" type="text/javascript">      
  $(document).ready(function() {  
 
    $( '#question{QID} li.question-item:eq(0) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(5) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(10) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(15) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(19) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(23) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(29) input.checkbox').css ({                     
      'display': 'none' 
    });
  });
</script>

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: marba
The topic has been locked.
More
8 years 11 months ago #119725 by marba
thank you both! I was going around different ways of referring to the question, and it seems it was never the right one! Still a lot to learn :laugh:
It's working now.
The topic has been locked.
More
5 years 1 month ago #180721 by krosser

tpartner wrote: I don't think you need to use scope here. Simple selectors should work.

Code:
<script charset="utf-8" type="text/javascript">      
  $(document).ready(function() {  
 
    $( '#question{QID} li.question-item:eq(0) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(5) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(10) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(15) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(19) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(23) input.checkbox').css ({                     
      'display': 'none' 
    });
    $( 'question{QID} li.question-item:eq(29) input.checkbox').css ({                     
      'display': 'none' 
    });
  });
</script>


Hi Tony,
Is there an update of this script for LS 3.15 and would it be different for the multiple-choice with comments?
I am trying to rewrite the "li.question-item:eq" and "input.checkbox" part, but to no avail.

I'm using the latest LS 3.22 hosted on LS servers, not installed locally.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose