Welcome to the LimeSurvey Community Forum

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

Mix groups randomly and replace exactly three by different version

  • whschreiber
  • whschreiber's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
9 years 4 months ago #115231 by whschreiber
Dear list,

after many hours... I gave up.

What poses no problem at all is putting the groups in random order, thus I don't mention this further.

Task:
One can formulate the problem in 2 ways, each lead to the same solution:

1) You have 9 szenarios version A and B.
- the szenarios are to be presented in random order
- exactly 3 have to be version A, the other 6 version B
(here the szenarios would be in 2x9 question groups)

2) You have 9 szenarios
- the szenarios have to be presented in random order
- for exactly 3 szenarios a number of questions within the question group should be presented

One could also say that we have a long and short version for each szenario.

My intended solution was:

a) In an initial group I have to equation-questions, assigning 9 to SZENE and 3 to USED

b) within each Szenario (following way 2) I pick a random number between 0 and 1

c) in the relevance-equation I check if the random number is smaller or larger than USED/SZENE

d1) If larger the longer version applies

d2) if smaller or equal the shorter version applies *and* USED = USED-1

e) at the end of the block in an equation-question I set SZENE = SZENE-1

In theory that works fine but USED and SZENE seem not to be global but local to the group defined in (a). The names however are reserved, e.g. I cannot use them in (d2) or (e) as question code.

Furthermore I can even display them in further questions but not manipulate, e.g. decrement them.

Any ideas? I would greatly appreciate any suggestions.

[ of course I work with intval(), etc. I just didn't mention it to keep it less cluttered ]

Best, Walter.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
9 years 4 months ago - 9 years 4 months ago #115244 by tpartner
So, if I understand correctly, you need to display 3 long versions and 6 short versions of the questions in random order.

I'm not sure you can get there with Expression Manager.

I would handle it using JavaScript and a hidden multiple-short-text question to control the display of the short/long versions.

1) Create 9 groups, each containing a long and short version of the same question (I suspect you have already done this). Display these in random order.

2) In a preceding group, add a multiple-short-text question (let's call it "control") with 9 sub-questions displayed in random order.

3) Add the following script to the "control" question. This will hide that question and populate its inputs. The first three inputs get a value of 1, the last six get a value of 2. (remember, the inputs are randomized, effectively giving them random values)
Code:
<script type="text/javascript" charset="utf-8">  
  $(document).ready(function() {
 
    // Identify this question
    var thisQuestion = $('#question{QID}');
 
    // Hide the question
    thisQuestion.hide();
 
    // Load the values
    if($('input.text:first', thisQuestion).val() == '') {
      $('input.text', thisQuestion).each(function(i) {
        if(i < 3) {
          $(this).val(1);
        }
        else {
          $(this).val(2);
        }
      });
    }
 
    });
</script>

4) Then you can use relevance based on the "control" question to show either the long or short question in each group. For example, something like this to for the long question in the first random group.
Code:
control_1 == '1'
And like this to for the short question in the first random group.
Code:
control_1 == '2'

Here's a working copy of the "control" question with that script in the source. (I have commented out the hide() function so you can see the values)

File Attachment:

File Name: limesurvey...5631.lsq
File Size:7 KB

Cheers,
Tony Partner

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

Lime-years ahead

Online-surveys for every purse and purpose