Welcome to the LimeSurvey Community Forum

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

fix an answer on 1st possition in randomized array

  • DanielVN
  • DanielVN's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 4 days ago #190561 by DanielVN
Hi All,

I have a survey where for the following list of answers in an array question I need to show the first answer (in blue) always at 1st possition and all others should be randomized:

Value-for-money ratio of fruit and vegetable products
Reliable and consistent quality of fruit and vegetable products
Good taste of fruit and vegetable products
Appetizing appearance of fruit and vegetable products
Long shelf-life of fruit and vegetable products at home
Information about origins of fruit and vegetable products
A large selection of fruit and vegetable products
Promotional offers for fruit and vegetables (e.g. leaflet-promotions)
The availability of fruit and vegetable products (few gaps in shelves)
The availability of promoted fruit and vegetable special offers.
The selection of organic fruit and vegetable products
The selection of regional fruit and vegetable products
The selection of exotic fruit and vegetable products (e.g. pomegranate, physalis, kaki)
The selection of snack products and pre-cut fruits and vegetables for instant consumption (e.g. freshly cut pineapple)
The selection of seasonal fruit and vegetable products (e.g. asparagus in spring and pumpkins in autumn)
The selection of different packaging and serving sizes for fruit and vegetable products
The selection of loosely fruits and vegetables
An attractive selection of private labels for fruit and vegetable products
The availability of innovative products (e.g. red basil, avocado-lime-chili-mix for Guacamole, etc.)
The cleanliness and hygiene of the fruit and vegetable section
An appealing presentation of products in the fruit and vegetable section
An inviting atmosphere in the fruit and vegetable section

Please advise how this can be achieved?

The question is Array and i'm using version 2.73

Thank you
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 4 days ago #190566 by tpartner
Can you attach a small sample survey (.lss file) containing only that question?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DanielVN
  • DanielVN's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 3 days ago #190608 by DanielVN
Hi TPartner,

Tahnk you. Please find attached the sample survey.

Cheers
Daniel

File Attachment:

File Name: limesurvey...3591.lss
File Size:27 KB
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 3 days ago - 5 years 3 days ago #190610 by tpartner
Initiate random order in the question settings and add a script like this to the question source:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:scriptcomplete',function(){
 
    // The sub-question code to be fixed in the first position
    var fixedCode = '1'; 
 
    var qID = '{QID}';
 
    // Move the sub-question
    $('#question'+qID+' table.subquestion-list tbody:eq(0)').prepend($('#question{QID} tr.answers-list[id$="X'+qID+fixedCode+'"]'));
 
    // Fix up the row background colours
    $('#question'+qID+' tr.answers-list').each(function(i){
      $(this).removeClass('array1, array2');
      if(i % 2 == 0) {
        $(this).addClass('array1');
      }
      else {
        $(this).addClass('array2');
      }
    });
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...5911.lss
File Size:30 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 3 days ago by tpartner.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose