Welcome to the LimeSurvey Community Forum

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

Partially randomized array in 3.*

  • dangerdangerhighvoltage
  • dangerdangerhighvoltage's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago - 4 years 5 months ago #189501 by dangerdangerhighvoltage
Partially randomized array in 3.* was created by dangerdangerhighvoltage
Hello helpful limesurvey forum <3


As always i tried to search the forum before, but the search wasn't fruitful. Neither is their an entry for this in the workaround documentation.

I want to randomize an array, but fix a certain amount of subquestions at the end (4 to be precise). Sadly, my whole experience with javascript is copying scripts from the documentation and slightly changing them. Is there such a thing and i am just blind, or can anyone avid with javascript experience help me out here? Much appreciated.
Last edit: 4 years 5 months ago by dangerdangerhighvoltage.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago #189503 by tpartner
Replied by tpartner on topic Partially randomized array in 3.*
Can you attach a small sample survey (.lss file) containing only the relevant question?

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: dangerdangerhighvoltage
The topic has been locked.
  • dangerdangerhighvoltage
  • dangerdangerhighvoltage's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
4 years 5 months ago #189509 by dangerdangerhighvoltage
Replied by dangerdangerhighvoltage on topic Partially randomized array in 3.*
Yes, i can. :)
Attachments:
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
4 years 5 months ago - 4 years 5 months ago #189518 by tpartner
Replied by tpartner on topic Partially randomized array in 3.*
He, he, I like the survey title.

Add a script like this to the question source:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // List of sub-question codes to be pinned to the bottom (in order)
    var sqCodes = ['8', '9', '10', '11'];
 
    // Identify this question
    var qID = '{QID}';
    var thisQuestion = $('#question'+qID);
 
    // Loop through the sub-question codes and reposition the corresponding row
    $.each(sqCodes, function(i, val) {
      var thisRow = $('tr[id^="javatbd"][id$="X'+qID+val+'"]');
      $('table.subquestion-list tbody:last', thisQuestion).append(thisRow);
    });  
    });
</script>

Here is your sample survey back with that script inserted:

File Attachment:

File Name: limesurvey...6878.lss
File Size:25 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 years 5 months ago by tpartner.
The following user(s) said Thank You: dangerdangerhighvoltage
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose