Welcome to the LimeSurvey Community Forum

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

Hide text boxes and fix some options at the end in a multi options with comments

  • Oterito
  • Oterito's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 weeks ago #241879 by Oterito
Please help us help you and fill where relevant:
Your LimeSurvey version: 3.28.54
Own server or LimeSurvey hosting: own
Survey theme/template: vanilla
==================
Hi! I need create a multi options with comments question hiding some of the text boxes and randomize options except the last 4.

I tried this [url] survey-consulting.com/how-to-place-a-cer...t-limesurvey-survey/ [/url]
 
The code for hide the text boxes works perfectly but the second part for fix the last options doesn’t work. 

could anyone help me pleace?

thank you in advance

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 weeks ago #241882 by tpartner
This script placed in the source of a multiple-choice type question will fix defined items at the end of the list (when order is randomized in the question settings).

You will need to modify the fixedItems values as required.

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    var fixedItems = ['SQ005', 'SQ006', 'SQ007', 'other'];
 
    //// NO EDITING REQUIRED BELOW HERE ////
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    $.each(fixedItems, function(e, code) {
      $('li[id$="'+code+'"]').appendTo($('.answers-list', thisQuestion));
    });
  });
</script>

Sample survey attached:  

File Attachment:

File Name: limesurvey...2931.lss
File Size:21 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: Oterito

Please Log in to join the conversation.

  • Oterito
  • Oterito's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 year 4 weeks ago #241920 by Oterito
Thanks Tony!
I had problems at first because I had the subquestion codes with only numbers, but then I added "SQ..." and ir worked perfectly.
Thank you very much!

Please Log in to join the conversation.

  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 year 4 weeks ago #241945 by tpartner
Sorry, I got a little lazy there. This script will handle numeric sub-question codes:

Code:
<script type="text/javascript" data-author="Tony Partner">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    var fixedItems = ['5', '6', '7', 'other'];
 
    //// NO EDITING REQUIRED BELOW HERE ////
 
    // Identify this question
    var qID = '{QID}';
    var thisQuestion = $('#question'+qID);
 
    $.each(fixedItems, function(e, code) {
      $('li[id$="'+qID+code+'"]').appendTo($('.answers-list', thisQuestion));
    });
  });
</script>

Sample survey: 

File Attachment:

File Name: limesurvey...2932.lss
File Size:21 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.

Please Log in to join the conversation.

  • Oterito
  • Oterito's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
8 months 1 week ago #245761 by Oterito
Hi Tony, i am trying to use this code in version 5.6.31 and it doesn't fix the variables at the end. Can you help me? Thanks in advance

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose