- Posts: 1
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
function insertSubHeading(qID, rowNum, text) { var thisQuestion = $('#question'+qID+''); var cols = $('table.subquestions-list thead td, table.subquestions-list thead th', thisQuestion).length; $('#question'+qID+' table.subquestions-list tbody tr:eq('+(rowNum-2)+')').after('<tr class="subHeading"><th class="answertext">'+text+'</th><td colspan="'+(cols-1)+'"></td></tr>'); }
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ insertSubHeading('{QID}', 3, 'SUBHEADING 1'); }); </script>
<strong>My sub heading</strong>
$("table.question tbody th > strong").each(function(){ $(this).closest("tr").addClass("sub-heading"); }
.sub-heading input{display:none} .sub-heading{background:#ccc}
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Call the function insertSubHeading('{QID}', 3, 'SUBHEADING 1'); }); function insertSubHeading(qID, rowNum, text) { // Identify some stuff var thisQuestion = $('#question'+qID+''); var cols = $('table.subquestion-list thead tr:eq(0) > *', thisQuestion).length; // Insert the new row $('#question'+qID+' table.subquestion-list tbody tr:eq('+(rowNum-1)+')').before('<tr class="subHeading"><th class="answertext">'+text+'</th><td colspan="'+(cols-1)+'"></td></tr>'); // Fix up the row classes var rowClass = 1; $('table.subquestion-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('subHeading')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); } </script>
insertSubHeading('{QID}', 1, 'Traditionele media'); insertSubHeading('{QID}', 4, 'Digi media');
tr.Subheading { background-color: purple; color: #ffffff; }
Bug here - www.limesurvey.org/forum/design-issues/1...rce-code-not-visibleSo it does seem to work indeed, although the code does seem to get removed upon re-editing the question (it's not visible in when using 'Source' and after saving again the subheadings are removed indeed from the preview).
Yes, if you like purple.To add a dash of colour to the subheadings I can add the following to my css file, right?
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Call the function insertSubHeading('{QID}', 1, 'Traditionele platformen'); insertSubHeading('{QID}', 8, 'Digitale platformen die niet horen bij bovenstaande &#39;traditionele media&#39;'); }); function insertSubHeading(qID, rowNum, text) { // Identify some stuff var thisQuestion = $('#question'+qID+''); var cols = $('table.subquestion-list thead tr:eq(0) > *', thisQuestion).length; // Insert the new row $('#question'+qID+' table.subquestion-list tbody tr:eq('+(rowNum-1)+')').before('<tr class="subHeading"><th class="answertext subHeading" colspan="'+(cols)+'">'+text+'</th></tr>'); // Fix up the row classes var rowClass = 1; $('table.subquestion-list tbody tr', thisQuestion).each(function(i) { if($(this).hasClass('subHeading')) { rowClass = 1 } else { rowClass++; $(this).removeClass('array1 array2') if(rowClass % 2 == 0) { $(this).addClass('array2'); } else { $(this).addClass('array1'); } } }); } </script>
/* Array table Subheading*/ .subHeading { background-color: #233140; color: #ffffff; font-weight: normal; padding-top: 1em !important; }