- Posts: 6
- 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(){ // The example text strings var column1Label = 'Examples'; var column1Example = '11:45 am'; var column2Example = 'Work'; var column3Example = '15oz'; // Identify the question var thisQuestion = $('#question{QID}'); // Create a fake row var newRow = $('tr.subquestion-list:eq(0)', thisQuestion).clone(); $(newRow).addClass('inserted-row'); $('input[type="text"]', newRow).removeAttr('id').removeAttr('name'); $('input[type="hidden"]', newRow).remove(); // Insert the example text strings $('.answertext', newRow).text(column1Label); $('input[type="text"]:eq(0)', newRow).val(column1Example); $('input[type="text"]:eq(1)', newRow).val(column2Example); $('input[type="text"]:eq(2)', newRow).val(column3Example); // Disable the fake row inputs $('input[type="text"]', newRow).prop('readonly', true); // Insert the fake row $('table.questions-list tbody:eq(0)', thisQuestion).prepend(newRow); // Fix up the row classes 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(){ // The example text strings var column1Label = 'Examples'; var column1Example = '11:45 am'; var column2Example = 'Work'; var column3Example = '15oz'; // Identify the question var thisQuestion = $('#question{QID}'); var thisArray = $('th.answertext:eq(0)', thisQuestion).closest('table'); // Create a fake row var newRow = $('tbody:eq(0) tr:eq(0)', thisArray).clone(); $(newRow).addClass('inserted-row'); $('input[type="text"]', newRow).removeAttr('id').removeAttr('name'); $('input[type="hidden"]', newRow).remove(); // Insert the example text strings $('.answertext', newRow).text(column1Label); $('input[type="text"]:eq(0)', newRow).val(column1Example); $('input[type="text"]:eq(1)', newRow).val(column2Example); $('input[type="text"]:eq(2)', newRow).val(column3Example); // Disable the fake row inputs $('input[type="text"]', newRow).attr('readonly', true); // Insert the fake row $('tbody:eq(0)', thisArray).prepend(newRow); // Fix up the row classes var rowClass = 1; $('tbody tr', thisArray).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>