Welcome to the LimeSurvey Community Forum

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

how to add several 'other' options to multiple choice question?

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 11 months ago #154845 by tpartner
Oh, wait, I have a typo in my code - use this:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // Identify this question
    var qID = {QID}; 
 
    // The sub-question codes to have no text input
    var sqCodes = [1, 2, 3, 4]; 
 
    // Loop through those sq codes and remove their text inputs
    $(sqCodes).each(function(i, code) {
      $('#question'+qID+' input[type="text"][id$="X'+qID+code+'comment"]').remove();
    });
 
    // The number of answers to be fixed at the end of the list
    var fixedAnswers = 2;
 
    // Find the number of answers
    var ansCount = $('#question'+qID+' .answer-item').length;
 
    // Place the last n answers created at the end of the list
    var fixedIndex = fixedAnswers - 1;
    for (var i=0; i<fixedAnswers; i++) {
      var answer = $('input[id^="answer"][id$="X'+qID+(ansCount-fixedIndex)+'"]');
      var answerItem = $(answer).closest('.answer-item');
      var answersList = $(answer).closest('.answers-list');
      if($('#question'+qID).hasClass('multiple-opt')) {
        answerItem = $(answer).closest('.answer-item').parent();
        answersList = $(answer).closest('.subquestion-list');
      }
      if($('#question'+qID).hasClass('multiple-opt-comments')) {
        answersList = $(answer).closest('tbody');
      }
      $(answersList).append(answerItem);
      fixedIndex--;
    }    
  });
</script>

Sample survey:

File Attachment:

File Name: limesurvey...7562.lss
File Size:29 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: BBCMResearch
The topic has been locked.
More
6 years 11 months ago #154847 by BBCMResearch
Thanks Tony, works like a charm!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose