- Posts: 1
- 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}'); // Index the array columns $('table.subquestions-list tr', thisQuestion).each(function(i) { $('> *', this).each(function(i) { $(this).attr('data-index', i); }); }); // Insert a button var buttonText = 'Load Answers'; $('.subquestions-list', thisQuestion).before('<button class="autofill" type="button">'+buttonText+'</button>'); // Click event on the button $('button.autofill', thisQuestion).on('click', function(e) { // Loop through row 1 answers and load following rows $('tr.subquestion-list:first input[type="text"]', thisQuestion).each(function(i) { var thisIndex = $(this).closest('td.answer-item').attr('data-index'); var thisValue = $(this).val(); $('td.answer-item[data-index="'+thisIndex+'"] input[type="text"]', thisQuestion).val(thisValue); }); }); }); </script>