- Posts: 6
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
However, when a respondent choose either one should also be restricted from the relevant checkbox option in another or vice versa.
<script type="text/javascript" charset="utf-8"> // A function to handle "secondary" checkboxes function secondaryCheckboxes(qID, primaryPosition, secondaryCount,primaryHide) { // Identify the elements var thisQuestion = $('#question'+qID); var primaryRow = $('li.question-item:eq('+(primaryPosition-1)+')', thisQuestion).closest('li.question-item'); var primaryInput = $('input:checkbox', primaryRow); var secondaryRows = primaryRow.nextAll('li.question-item:lt('+(secondaryCount)+')'); var secondaryInputs = $('input:checkbox', secondaryRows); var primaryHRow = $('li.question-item:eq('+(primaryHide-1)+')', thisQuestion).closest('li.question-item'); // Indent the secondaries secondaryRows.css({ 'margin-left':'2.5em' }); // Initial states of the secondary answers if (primaryInput.prop('checked') == false ) { secondaryRows.hide(); } // A listener on the primary answer to show or hide secondary answers primaryInput.on('change', function (event) { // Hide/show the secondary answers accordingly if (!$(this).is(':checked')) { primaryHRow.show(); secondaryRows.hide(); secondaryInputs.prop('checked', false).trigger('change'); } else { secondaryRows.show(); primaryHRow.hide(); } }); } $(document).ready(function() { // Sub-question 1 is primary followed by 3 secondaries // Sub-question 5 is to hide if 1 is checked secondaryCheckboxes({QID}, 1, 3, 5); // Sub-question 5 is primary followed by 3 secondaries // Sub-question 1 is to hide if 5 is checked secondaryCheckboxes({QID}, 5, 3, 1); }); </script>
Joffm wrote: Hi,
I think this fulfills your wish.However, when a respondent choose either one should also be restricted from the relevant checkbox option in another or vice versa.
And if the primary checkbox is unchecked you see the initial "Yes/No" again.
I added a little bit to this - custom - workaround that you find here:
www.limesurvey.org/manual/Workarounds:_M...meSurvey_version_3.x
Code:<script type="text/javascript" charset="utf-8"> // A function to handle "secondary" checkboxes function secondaryCheckboxes(qID, primaryPosition, secondaryCount,primaryHide) { // Identify the elements var thisQuestion = $('#question'+qID); var primaryRow = $('li.question-item:eq('+(primaryPosition-1)+')', thisQuestion).closest('li.question-item'); var primaryInput = $('input:checkbox', primaryRow); var secondaryRows = primaryRow.nextAll('li.question-item:lt('+(secondaryCount)+')'); var secondaryInputs = $('input:checkbox', secondaryRows); var primaryHRow = $('li.question-item:eq('+(primaryHide-1)+')', thisQuestion).closest('li.question-item'); // Indent the secondaries secondaryRows.css({ 'margin-left':'2.5em' }); // Initial states of the secondary answers if (primaryInput.prop('checked') == false ) { secondaryRows.hide(); } // A listener on the primary answer to show or hide secondary answers primaryInput.on('change', function (event) { // Hide/show the secondary answers accordingly if (!$(this).is(':checked')) { primaryHRow.show(); secondaryRows.hide(); secondaryInputs.prop('checked', false).trigger('change'); } else { secondaryRows.show(); primaryHRow.hide(); } }); } $(document).ready(function() { // Sub-question 1 is primary followed by 3 secondaries // Sub-question 5 is to hide if 1 is checked secondaryCheckboxes({QID}, 1, 3, 5); // Sub-question 5 is primary followed by 3 secondaries // Sub-question 1 is to hide if 5 is checked secondaryCheckboxes({QID}, 5, 3, 1); }); </script>
Joffm