- Posts: 3
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
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() { // Identify this question var thisQuestion = $('#question{QID}'); // Identify the "exclusive" column(s) // Multiple columns separated by commas var exclusiveCols = [1,2]; // Assign classes to various elements $('tr[id^="javatbd"]', thisQuestion).each(function(i){ var column = 1; var scale = 1; $('td', this).each(function(i) { if($(this).hasClass('answer-item')) { $(this).addClass('scale-'+scale+' column-'+column+''); column++; } else if(scale == 1 && $(this).hasClass('dual_scale_separator')) { column = 1; scale = 2; } else if(scale == 2 && $(this).hasClass('dual_scale_separator')) { column = 1; scale = 3; } }); $('td.scale-2:last', this).addClass('na-item'); }); $(exclusiveCols).each(function(i) { $('td.scale-1.column-'+this, thisQuestion).addClass('exclusive-item'); }); // Hide the "N/A" column var naIndex = $('td.na-item:eq(0)', thisQuestion).index(); $('td.na-item', thisQuestion).hide(); $('.questions-list .dsheader:last', thisQuestion).attr('colspan', Number($('.questions-list thead tr.groups .dsheader:last', thisQuestion).attr('colspan'))-1); $('.questions-list thead tr:not(.groups) th.answer-text:not(.noanswer-text):last', thisQuestion).hide(); $('colgroup.group-2 col:last', thisQuestion).hide(); // Listener on the radios $('td.scale-1 input:radio', thisQuestion).on('click', function(e) { var thisCell = $(this).closest('td'); var thisRow = thisCell.closest('tr'); var thisNA = $('.na-item input:radio', thisRow); var naValue = ''; if(thisCell.hasClass('exclusive-item')) { naValue = thisNA.val(); thisNA.trigger('click'); $('td.scale-2:not(.na-item) input:radio', thisRow).prop('disabled', true); } else { thisNA.prop('checked', false); $('td.scale-2:not(.na-item) input:radio', thisRow).prop('disabled', false); } // Fire ExpressionScript naName = thisNA.attr("name"); naName = naName.replace('#', '_'); $("#java" + naName).val(naValue); ExprMgr_process_relevance_and_tailoring('change', naValue, 'radio'); }); // Initial states $('td.exclusive-item input:radio:checked', thisQuestion).each(function(i) { var thisRow = $(this).closest('tr'); console.log(thisRow); $('.na-item input:radio', thisRow).trigger('click'); $('td.scale-2:not(.na-item) input:radio', thisRow).prop('disabled', true); }); }); </script>