- Posts: 11
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var qID = '{QID}'; var thisQuestion = $('#question'+qID); // Add column-specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('> *', 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[id^="javatbd"]:first 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 column $('.checkbox-item[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('disabled', false); if ($(thisCell).hasClass('normal-opt') && $(thisCheckBox).is(':checked')) { $('.exclusive-opt[data-column="'+thisColumn+'"] input:hidden', thisQuestion).val(''); $('.exclusive-opt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('checked', false).trigger('change'); } else if ($(thisCheckBox).is(':checked')) { $('.normal-opt[data-column="'+thisColumn+'"] input:hidden', thisQuestion).val(''); $('.normal-opt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('checked', false).trigger('change').prop('disabled', true); } } }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var qID = '{QID}'; var thisQuestion = $('#question'+qID); // Add column-specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('> *', 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[id^="javatbd"]:first td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt'); $('tr[id^="javatbd"]:first td.checkbox-item:last', thisQuestion).addClass('master-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 column $('.checkbox-item[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('disabled', false); if ($(thisCell).hasClass('master-exclusive-opt') && $(thisCheckBox).is(':checked')) { $('td.checkbox-item:not(.master-exclusive-opt) input:hidden', thisQuestion).val(''); $('td.checkbox-item:not(.master-exclusive-opt) input[type="checkbox"]', thisQuestion).prop('checked', false).trigger('change').prop('disabled', true); } else if ($(thisCell).hasClass('normal-opt') && $(thisCheckBox).is(':checked')) { $('.exclusive-opt[data-column="'+thisColumn+'"] input:hidden', thisQuestion).val(''); $('.exclusive-opt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('checked', false).trigger('change'); } else if ($(thisCheckBox).is(':checked')) { $('.normal-opt[data-column="'+thisColumn+'"] input:hidden', thisQuestion).val(''); $('.normal-opt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('checked', false).trigger('change').prop('disabled', true); } } }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ var qID = '{QID}'; var thisQuestion = $('#question'+qID); // Add column-specific classes $('tr.subquestion-list', thisQuestion).each(function(i) { $('> *', 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[id^="javatbd"]:first td.checkbox-item', thisQuestion).removeClass('normal-opt').addClass('exclusive-opt'); $('tr[id^="javatbd"]:first td.checkbox-item:last', thisQuestion).addClass('master-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 column $('.checkbox-item[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('disabled', false); if ($(thisCell).hasClass('master-exclusive-opt') && $(thisCheckBox).is(':checked')) { $('.checkbox-item[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('disabled', false); $('td.checkbox-item:not(.master-exclusive-opt) input:hidden', thisQuestion).val(''); $('td.checkbox-item:not(.master-exclusive-opt) input[type="checkbox"]', thisQuestion).prop('checked', false).trigger('change').prop('disabled', true); } else if ($(thisCell).hasClass('master-exclusive-opt')) { $('.checkbox-item input[type="checkbox"]', thisQuestion).prop('disabled', false); } else if ($(thisCell).hasClass('normal-opt') && $(thisCheckBox).is(':checked')) { $('.exclusive-opt[data-column="'+thisColumn+'"] input:hidden', thisQuestion).val(''); $('.exclusive-opt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('checked', false).trigger('change'); } else if ($(thisCheckBox).is(':checked')) { $('.normal-opt[data-column="'+thisColumn+'"] input:hidden', thisQuestion).val(''); $('.normal-opt[data-column="'+thisColumn+'"] input[type="checkbox"]', thisQuestion).prop('checked', false).trigger('change').prop('disabled', true); } } }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.