Welcome to the LimeSurvey Community Forum

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

Capturing randomization order

More
5 years 2 months ago - 5 years 2 months ago #201328 by elenas
It doesn't work. My first question of the group is an array.


This new script works if the first question is a radio.

Thanks

ps. I have version 2.06
Last edit: 5 years 2 months ago by elenas.
The topic has been locked.
More
5 years 2 months ago #201442 by tpartner
What are you trying to capture? The answers (x-scale) are not randomized.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
5 years 2 months ago #201469 by elenas
Hi!
I want to capture the order of sub-questions (Germany, Cina, USA, ...).

By editing your script I get this: "b-1,b-2,b-3,...,b-10,a-1,a-2,a-3,...,a-10,d-1,...,d-10,c-1,....c-10"

Is it possible to write it in this way "b,a,d,c" ?

Thanks
Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function(){
 
    // Identify some stuff
    var qHiddenID = {QID}; // The hidden question ID
    var qHidden = $('#question'+qHiddenID); // The hidden question
    var q1 = $('div.array-10-pt:eq(0)'); // First array question on the page
    var q1ID = $(q1).attr('id').split('question')[1]; // The first array question ID
    var gID = $('input:text', qHidden).attr('id').split('X')[1]; // The group ID
 
    // Hide this question
    $(qHidden).hide();
 
    // Build an array of the Q1 answers
    var answersArr = [];
    $('input:radio', q1).each(function(i){
      var answerID = $(this).attr('id').split('X'+gID+'X'+q1ID)[1];
      answersArr.push(answerID);
    });
 
    // Load the array into the hidden question
    $('input:text', qHidden).val(answersArr);
  });
</script>
The topic has been locked.
More
5 years 2 months ago - 5 years 2 months ago #201495 by tpartner
Try this:

Code:
<script type="text/javascript" charset="utf-8">
 
  $(document).ready(function(){
 
    // Identify some stuff
    var qHiddenID = {QID}; // The hidden question ID
    var qHidden = $('#question'+qHiddenID); // The hidden question
    var q1 = $('table.subquestions-list:eq(0)').closest('div[id^="question"]'); // First array question on the page
    var q1ID = $(q1).attr('id').split('question')[1]; // The first array question ID
    var gID = $('input:text:eq(0)', qHidden).attr('id').split('X')[1]; // The group ID
 
    // Hide this question
    $(qHidden).hide();
 
    // Build an array of the Q1 answers
    var answersArr = [];
    $('tr[id^="javatbd"]', q1).each(function(i){
      var answerID = $(this).attr('id').split('X'+gID+'X'+q1ID)[1];
      answersArr.push(answerID);
    });
 
    // Load the array into the hidden question
    $('input:text', qHidden).val(answersArr).trigger('keyup');
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...2282.lss
File Size:24.17 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 5 years 2 months ago by tpartner.
The following user(s) said Thank You: elenas
The topic has been locked.
More
5 years 2 months ago #201521 by elenas
It works!
Thank you
The topic has been locked.
More
4 years 10 months ago - 4 years 10 months ago #205819 by LookingforSolution
Hello,

I would like to randomize multi punch question items in blocks. I do have an exclusive option (always at the end) and a not open "other" option (at the second last position):

A--> Block 1
B--> Block 1
C--> Block 1
D--> Block 2
E--> Block 2
F--> Block 2
G--> Block 3
Other-->Block 3
Exclusive--> Block 3


For that reason, I created separate questions for every item-block (1st question with question text, others without) within the same question group and added the same randomization group name for all questions.

I used the follwing skripts:

1. For first question Block1 (items with question text):

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#question{QID}').addClass('no-bottom');
});
</script>

2. for following question Block 2-3 (only items, no question text):

<script type="text/javascript" charset="utf-8">
$(document).ready(function(){
$('#question{QID}').addClass('no-question');
$('#question{QID}').addClass('no-bottom');
});
</script>

The problems are the following:

1. I want the questions always to be answered, but I can only put every question for itself as obligatory. This means one item of every question has to be selected, which does not always make sense.
2. If the exclusive option is selected ALL other items from all questions of this group should be grayed out. This right now only applies to items, which are in the same block.

Could you maybe help?
Thanks in advance!

File Attachment:

File Name: limesurvey...3629.lss
File Size:27.59 KB
Last edit: 4 years 10 months ago by LookingforSolution.
The topic has been locked.
Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose