- Posts: 11
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the exclusiveArrayRows function with question and sub-question IDs var sqIDs = ['SQ001', 'SQ002'] exclusiveArrayRows2({QID}, sqIDs); }); // A function to conditionally disable array answers // Parameters: // 1) The question ID // 2) An array of sub-question IDs to be exclusive function exclusiveArrayRows2(qID, sqIDs) { // Identify the question var thisQuestion = $('#question'+qID); // Loop through the sub-question IDs $(sqIDs).each(function(i, val) { // Assign a class $('tr.answers-list[id$="X'+qID+val+'"]', thisQuestion).addClass('conditional-row'); }); // Initial radio states $('.conditional-row input.radio:checked', thisQuestion).each(function(i) { // Call a function to handle the radios handleRadios($(this), $(this).val()); }); // Listener on the exclusive radios $('.conditional-row input.radio', thisQuestion).on('click', function(e) { // Call a function to handle the radios handleRadios($(this), $(this).val(), true); }); // A function to disable/enable radios function handleRadios(checkedRadio, thisValue, onClick) { var thisRow = $(checkedRadio).closest('tr.answers-list'); var otherRows = $('tr.answers-list.conditional-row', thisQuestion).not(thisRow); if(onClick !== undefined) { // Reset the other rows on click $('input.radio', otherRows).prop('disabled', false); } //Determine which radios to disable var disabledInputs = $('input.radio', otherRows).filter(function(e) { return $(this).val() ==thisValue; }); // Disable the appropriate radios in the other rowss $(disabledInputs).prop('checked', false).prop('disabled', true); } } </script>