Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Array question: possible to repeat answers from first column

  • chris78
  • chris78's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 years 3 months ago #128847 by chris78
Dear forum users

This is the first time I am using LimeSurvey and I apologize if I have overlooked the answer to my question in the manual or previous forum posts...
My question relates to an "array question" with 8 x 11 subquestions and text filling. If this "table" has to be filled cell by cell, it will be very tedious; especially, since from column to column probably several cells/answers will stay the same and only some will change. Therefore, my wish would be to to include something like an "autofill button" that one could click after filling the first column, so that all other columns would be filled with the same "default" values, and that could then be adapted manually.

Is there such a thing in LimeSurvey?

Thank you very much for your help!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 years 3 months ago #128873 by tpartner
There is no built-in method for this but we can do it with a little JavaScript.

1) Set up your survey to use JavaScript .

2) Add this script to the source of the array:
Code:
<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>

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose