- Posts: 28
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Array numbers with checkbox and an exclusive option
- stephanied
- Offline
- Junior Member
Less
More
5 years 11 months ago - 5 years 11 months ago #168866
by stephanied
Replied by stephanied on topic Array numbers with checkbox and an exclusive option
My apologies. Are you more so looking for the survey structure (.lss)?
Attachments:
Last edit: 5 years 11 months ago by stephanied.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10115
- Thank you received: 3597
5 years 11 months ago #168915
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 Array numbers with checkbox and an exclusive option
This script will render the last row of an array-checkboxes as exclusive. Additionally, when a check-box in the last row is checked, all other check-boxes in that column are disabled.
Here is your test survey back with that script in the source of the array:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { var thisQuestion = $('#question{QID}') // Add column-specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('th, td', this).each(function(i) { $(this).addClass('column-'+i).attr('data-column', i); }); }); // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normal-opt'); $('tr.subquestion-list:last td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt'); // A listener on the checkboxes $('td.checkbox-item input[type="checkbox"]', thisQuestion).change(function (event) { handleExclusive($(this).closest('td')); }); function handleExclusive(thisCell) { var thisColumn = $(thisCell).attr('data-column'); var thisCheckBox = $('input[type="checkbox"]', thisCell); // Uncheck the appropriate boxes in a row $('.checkbox-item[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('disabled', false); if ($(thisCell).hasClass('normal-opt') && $(thisCheckBox).is(':checked')) { $('.exclusive-opt[data-column="'+thisColumn+'"] input:hidden').val(''); $('.exclusive-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false); } else if ($(thisCheckBox).is(':checked')) { $('.normal-opt[data-column="'+thisColumn+'"] input:hidden').val(''); $('.normal-opt[data-column="'+thisColumn+'"] input[type="checkbox"]').prop('checked', false).prop('disabled', true); } // Check conditions (relevance) $('td.checkbox-item[data-column="'+thisColumn+'"]').each(function(i) { var thisValue = ''; var itemCheckBox = $('input[type="checkbox"]', this); var thisSGQA = $(itemCheckBox).attr('id').replace(/cbox_/, ''); var aelt = $('#answer'+thisSGQA); fixnum_checkconditions($(aelt).val(), thisSGQA, 'hidden'); checkconditions($(itemCheckBox).attr('value'), $(itemCheckBox).attr('name'), $(itemCheckBox).attr('type')) }); } }); </script>
Here is your test survey back with that script in the source of the array:
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.