- Posts: 7
- Thank you received: 0
Ask the community, share ideas, and connect with other LimeSurvey users!
Please Log in to join the conversation.
So thew profiles are there already and are not generated during the survey.Each respondent should see 10 different random profile pairs (profiles A and B drawn randomly from the pool of 2,880, applying the name restriction)
Depends, hidden field is easier, but you should show more details about it.Should profiles be stored in a hidden field or database?
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var thisQuestion = $('#question{QID}'); // Move the radios $('.question-text table:eq(0) tr:eq(3) td:eq(1)', thisQuestion).prepend($('.subquestion-list .answers-list:eq(0) .answer-item:eq(0) *', thisQuestion)); $('.question-text table:eq(0) tr:eq(3) td:eq(2)', thisQuestion).prepend($('.subquestion-list .answers-list:eq(0) .answer-item:eq(1) *', thisQuestion)); // and so on // Some classes for presentation $('.question-text table:eq(0) input:radio', thisQuestion).closest('td').addClass('answer-item radio-item text-center radio'); $('.question-text table:eq(0) .radio-item label', thisQuestion).show(); // Click event on the table cells $('.question-text table:eq(0) .radio-item', thisQuestion).on('click', function(e) { $('input:radio', this).trigger('click'); }); $('.question-text table:eq(0) input:radio', thisQuestion).on('click', function(e) { e.stopPropagation(); }); // Followed by some cleaning
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
<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 array with 20 characters var arr = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T"]; arr = shuffle(arr).join(''); $('#question{QID} input[type="text"]:eq(0)').val(arr); // Fill the array, numbers from 1 to 144 var arr1 = ; for (var i = 1; i < 145; i++) { var x = i.toString().padStart(4,"0").slice(-3); arr1.push(x); } arr1 = shuffle(arr1).slice(0, 20).join(''); $('#question{QID} input[type="text"]:eq(1)').val(arr1); //$('#question{QID}').hide(); }); </script>
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Verstecke den „Weiter“-Button $('#ls-button-submit').hide(); $('#ls-button-previous').hide(); setTimeout(function () { $('#ls-button-submit').trigger('click'); }, 3000); // 3 Seconds, Value in milliseconds }); </script>
{PName1=substr(QSelect_1,0,1)} {PComb_1=substr(Pool,strpos(Pool,join(substr(QSelect_2,0,3),':'))+4,4)} {PName2=substr(QSelect_1,1,1)} {PComb_2=substr(Pool,strpos(Pool,join(substr(QSelect_2,3,3),':'))+4,4)} {PField1=substr(PComb_1,0,1)} {PField2=substr(PComb_2,0,1)} {PGrade1=substr(PComb_1,1,1)} {PGrade2=substr(PComb_2,1,1)} {PActive1=substr(PComb_1,2,1)} {PActive2=substr(PComb_2,2,1)} {PSem1=substr(PComb_1,3,1)} {PSem2=substr(PComb_2,3,1)}
{PName1=substr(QSelect_1,2,1)} {PComb_1=substr(Pool,strpos(Pool,join(substr(QSelect_2,6,3),':'))+4,4)} {PName2=substr(QSelect_1,3,1)} {PComb_2=substr(Pool,strpos(Pool,join(substr(QSelect_2,9,3),':'))+4,4)} {PField1=substr(PComb_1,0,1)} {PField2=substr(PComb_2,0,1)} {PGrade1=substr(PComb_1,1,1)} {PGrade2=substr(PComb_2,1,1)} {PActive1=substr(PComb_1,2,1)} {PActive2=substr(PComb_2,2,1)} {PSem1=substr(PComb_1,3,1)} {PSem2=substr(PComb_2,3,1)}
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse:collapse;" width="100%"> <tbody> <tr> <td>Which profile do you prefer?</td> <td><strong>Profile 1</strong></td> <td><strong>Profile 2</strong></td> </tr> <tr> <td>Name</td> <td><strong>{PName1.shown}</strong></td> <td><strong>{PName2.shown}</strong></td> </tr> ... <tr> <td>Semester</td> <td><strong>{PSem1.shown}</strong></td> <td><strong>{PSem2.shown}</strong></td> </tr> <tr> <td><b>Your choice</b></td> <td> </td> <td> </td> </tr> </tbody> </table>
<script type="text/javascript" charset="utf-8"> $(document).on('ready pjax:scriptcomplete',function(){ // Identify this question var thisQuestion = $('#question{QID}'); // Move the radios, you see they are inserted in the second and third column (td:eq(x)) of the last row (tr:last) // And the first and second answer option are affected (answer-item:eq(x)) // Remember it is zero based. $('.question-text table:eq(0) tr:last td:eq(1)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .answer-item:eq(0) *', thisQuestion)); $('.question-text table:eq(0) tr:last td:eq(2)', thisQuestion).append($('.subquestion-list .answers-list:eq(0) .answer-item:eq(1) *', thisQuestion)); // Some classes for presentation $('.question-text table:eq(0) input:radio', thisQuestion).closest('td').addClass('answer-item radio-item text-center radio'); $('.question-text table:eq(0) .radio-item label', thisQuestion).show(); // Click event on the table cells $('.question-text table:eq(0) .radio-item', thisQuestion).on('click', function(e) { $('input:radio', this).trigger('click'); }); $('.question-text table:eq(0) input:radio', thisQuestion).on('click', function(e) { e.stopPropagation(); }); // Clean-up styles $('.answer-container', thisQuestion).hide(); $('.question-text table:eq(0) .label-text', thisQuestion).remove(); $('.question-text table:eq(0) .radio-text', thisQuestion).css({ 'cursor': 'pointer' }); }); </script>
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
You see that all 20 names are randomised and used one by one. So no name will appear twice.Q1: Name Restriction
1. 70:30 is not possibly. That's mathematics. To get 70% mixed pairs you need 7 names. Now there are 3 names left. One pair and a single one.Q2: Weighted Randomization by Ethnicity
You have to distinguish two cases.Q3: Multilingual Survey (English + German)
Please Log in to join the conversation.
$(document).on('ready pjax:scriptcomplete',function(){ // Split the array (a1: German names, a2: Turkish names) var a1 = ["A","B","C","D","E","F","G","H","I","J"]; var a2 = ["K","L","M","N","O","P","Q","R","S","T"]; // Shuffle both arrays a1 = shuffle(a1); a2 = shuffle(a2); // Create a random number that returns 6 or 8 number=6+2*Math.floor(Math.random() * 2); // Create the empty final array var aFin = ; // In a loop from 0 to the calculated number (6 or 8) for (var i = 0; i < number; i++) { // Create a new temporary array var aTmp = ; // where you push the German "name" and the Turkish "name" at position i // You get "number" pairs of different ethnicity aTmp.push(a1[i]); aTmp.push(a2[i]); // Shuffle this array that the order of "German" - "Turkish" is always different aTmp = shuffle(aTmp).join(''); // Push this array of two names into the final array aFin.push(aTmp); } // Now you care about the rest // In a loop from "number" to 10 with a step of 2 for (var i = number; i < 10; i+=2) { // Create a new temporary array var aTmp = ; // where you push the German "name" at position i and the "name" at position i+1 aTmp.push(a1[i]); aTmp.push(a1[i+1]); aTmp = shuffle(aTmp).join(''); aFin.push(aTmp); var aTmp = ; // here you push the Turkish "name" at position i and the "name" at position i+1 aTmp.push(a2[i]); aTmp.push(a2[i+1]); aTmp = shuffle(aTmp).join(''); aFin.push(aTmp); } // Now the array aFin looks like [ BM, IR, SG, OA, CQ, KF, DE, JH, LN, PO ] // Six pairs of different ethnicity, followed by two German pairs and two Turkish pairs // This array again is shuffled aFin = shuffle(aFin).join(''); // and finally you get the desired string like JHCQIRDEPOKFSGLNBMOALN $('#question{QID} input[type="text"]:eq(0)').val(aFin); //$('#question{QID}').hide(); });
var number=1+Math.floor(Math.random() * 100); if (number<3) { number=0; } else if (number<8) { number=2; } else if (number<18) { number=4; } else if (number<48) { number=6; } else if (number<78) { number=8; } else { number=10; }
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.
Please Log in to join the conversation.