- Posts: 12
- 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() { // Identify this question var thisQuestion = $('#question{QID}'); var columnsLength = $('tr.answers-list:eq(0) > *', thisQuestion).length; var found = { 'de0': false, 'be0': false, 'bg0': false, 'dk0': false, 'ee0': false, }; var position = { 'de0': '0', 'be0': '7', 'bg0': '11', 'dk0': '16', 'ee0': '21', } var name = { 'de0': 'Germany', 'be0': 'Belgium', 'bg0': 'Bulgaria', 'dk0': 'Denmark', 'ee0': 'Estonia', } var find = [ 'de0', 'be0', 'bg0', 'dk0', 'ee0' ]; $('tr.answers-list:visible').each(function(){ var identifier = $(this).attr('id'); $.each(find, function(index, value){ if(identifier.indexOf(value) !== -1) { found[value] = true; } }); }); var found_keys = Object.keys(found); console.log(found_keys); $.each(found_keys, function(index, value){ if(found[value]) { $('tr.answers-list:eq(' + position[value] + ')').before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+name[value]+'</th></tr>'); } }); var rowClass = 1; $('table.subquestions-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('sub-header-row')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); }); </script> <script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var thisQuestion = $('#question{QID}'); var columnsLength = $('tr.answers-list:eq(0) > *', thisQuestion).length; var found = { 'de0': false, 'be0': false, 'bg0': false, 'dk0': false, 'ee0': false, }; var position = { 'de0': '0', 'be0': '7', 'bg0': '11', 'dk0': '16', 'ee0': '21', } var name = { 'de0': 'Germany', 'be0': 'Belgium', 'bg0': 'Bulgaria', 'dk0': 'Denmark', 'ee0': 'Estonia', } var find = [ 'de0', 'be0', 'bg0', 'dk0', 'ee0' ]; $('tr.answers-list:visible').each(function(){ var identifier = $(this).attr('id'); $.each(find, function(index, value){ if(identifier.indexOf(value) !== -1) { found[value] = true; } }); }); var found_keys = Object.keys(found); console.log(found_keys); $.each(found_keys, function(index, value){ if(found[value]) { $('tr.answers-list:eq(' + position[value] + ')').before('<tr class="sub-header-row"><th colspan="'+columnsLength+'">'+name[value]+'</th></tr>'); } }); var rowClass = 1; $('table.subquestions-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('sub-header-row')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); }); </script>