Welcome to the LimeSurvey Community Forum

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

Anchoring subquestion in multiple choice question

  • jfrey1
  • jfrey1's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 9 months ago #201537 by jfrey1
Hello. I'd like to know how to anchor a subquestion in a multiple choice question using randomization. Attached is a test survey containing 2 examples of this scenario:

Test question #1: contains 4 subquestions
Test question #2: contains 5 subquestions, including an exclusive option ("None of the above"), which is automatically anchored; in this question, I'd like to anchor "Other" above "None of the above" in the list

Any questions, just let me know.

Lime version: Version 4.3.0+200616
The topic has been locked.
  • jfrey1
  • jfrey1's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 9 months ago #201885 by jfrey1
Can someone help me out please?
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 9 months ago #201890 by tpartner
Question 1, something like this in the script field:

Code:
// Sub-question code to be fixed at the bottom
var fixedCode = '4';
 
// Move the sub-question
$('#question{QID} .answers-list >ul:eq(0)').append($('#question{QID} li[id^="javatbd"][id$="X{QID}'+fixedCode+'"]'));

Question 2, something like this in the script field:

Code:
// Sub-question code to be fixed at second-bottom
var fixedCode = '4';
 
// Move the sub-question
$('#question{QID} li[id^="javatbd"]:last').before($('#question{QID} li[id^="javatbd"][id$="X{QID}'+fixedCode+'"]'));



Sample survey attached:

File Attachment:

File Name: limesurvey...3(1).lss
File Size:32 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • jfrey1
  • jfrey1's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 9 months ago #201891 by jfrey1
How do I access the script field to add code to a question? I imported the attached test survey, and I see the script in "Question overview" mode, but when I switch to "Question editor," the script is replaced with the "Help" entry field.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 9 months ago - 3 years 9 months ago #201892 by tpartner
You may not have permissions to insert scripts.

Try this in the question source:

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).on('ready pjax:scriptcomplete',function(){
    // Sub-question code to be fixed at the bottom
    var fixedCode = '4';
 
    // Move the sub-question
    $('#question{QID} .answers-list >ul:eq(0)').append($('#question{QID} li[id^="javatbd"][id$="X{QID}'+fixedCode+'"]'));
    });
</script>

Code:
<script type="text/javascript" charset="utf-8">  
  $(document).on('ready pjax:scriptcomplete',function(){
    // Sub-question code to be fixed at second-bottom
    var fixedCode = '4';
 
    // Move the sub-question
    $('#question{QID} li[id^="javatbd"]:last').before($('#question{QID} li[id^="javatbd"][id$="X{QID}'+fixedCode+'"]'));
    });
</script>

More about inserting JS here - manual.limesurvey.org/Workarounds:_Manip...tc..29_in_LimeSurvey

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 3 years 9 months ago by tpartner.
The topic has been locked.
  • jfrey1
  • jfrey1's Avatar Topic Author
  • Offline
  • Junior Member
  • Junior Member
More
3 years 9 months ago #201894 by jfrey1
This works, thanks!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose