Welcome to the LimeSurvey Community Forum

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

Customised Rotation for Radio and Check Box

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
1 day 19 hours ago - 1 day 19 hours ago #271315 by rajkumar_dms
Customised Rotation for Radio and Check Box was created by rajkumar_dms
[object Object] Please help us help you and fill where relevant:
LimeSurvey version: [6.15]
Own server or LimeSurvey Cloud:Cloud
Survey theme/template:
==================
Hello Good Day!

I need a customised rotation for Radio and check boxMy goal is to randomize the list of answers, but with flexibility to:
  • Fix certain answers at the top
  • Fix certain answers at the bottom
  • Fix some answers in their current position
  • ✅ If no answers are fixed (falsee), then fully randomize all answers
it can possible in the lime survey
Last edit: 1 day 19 hours ago by rajkumar_dms.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 day 17 hours ago - 1 day 17 hours ago #271318 by Joffm
You can do this.

The question "randOrder" is a question of type "short text" where you generate your order with a small script
like this
Code:
<script type="text/javascript" charset="utf-8">
 
    function shuffle(array) {
        var currentIndex = array.length, temporaryValue, randomIndex;
        // While there remain elements to shuffle...
        while (0 !== currentIndex) {
            // Pick a remaining element...
            randomIndex = Math.floor(Math.random() * currentIndex);
            currentIndex -= 1;
            // And swap it with the current element.
            temporaryValue = array[currentIndex];
            array[currentIndex] = array[randomIndex];
            array[randomIndex] = temporaryValue;
        }
        return array;
    }
 
$(document).on('ready pjax:scriptcomplete',function(){
    // Fill the arrays
    var arrTopFix = [1,2] ;
    var arrRand = [3,4,5,6];
    var arrBottomFix = [7] ;
    var arrTotal = ;
 
    arrTopFix = arrTopFix.join(',');
    arrRand = shuffle(arrRand).join(',');;
    arrBottomFix = arrBottomFix.join(',');
 
    arrTotal=arrTopFix.concat(',',arrRand,',',arrBottomFix);
    $('#question{QID} input[type="text"]').val(arrTotal);
 
    // Nach dem Testen in dieser letzten Zeile die Schrägstriche entfernen
    //$('#question{QID}').hide();
});
</script>

Here you may adapt the three arrays to your needs.

Now you use the script to maintain a randomization order.
Code:
<script type="text/javascript" data-author="Tony Partner">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    //Identify this question
    var thisQuestion = $('#question{QID}');
    var thisAnswerList = $('tr.answers-list:eq(0)', thisQuestion).parent();
 
  // Retrieve the answer codes from the "randOrder" question
    var answerCodes = '{randOrder}'.split(',');
 
    // Loop through the answer codes
    $.each(answerCodes, function(i, val) {
      // Move the answer item
      $(thisAnswerList).append($('tr.answers-list[id$="X{QID}'+val+'"]', thisQuestion));
    });
 
  });
</script>

The above script is for "array" questions.
For "multiple" questions you have to change this to
      // Move the answer item
      $(thisAnswerList).append($('li.checkbox-text-item[id$="X{QID}'+val+'"]', thisQuestion));

And for "list(radio)" to
      // Move the answer item
      $(thisAnswerList).append($('li.answer-item[id$="X{QID}'+val+'"]', thisQuestion));





Regarding this
Fix some answers in their current position
Here you may randomize all codes except these answers; then put them back to their position with function "splice()"
[url] www.w3schools.com/jsref/jsref_splice.asp [/url]
Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 1 day 17 hours ago by Joffm.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose