- Posts: 21
- Thank you received: 3
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Randomising MaxDiff (ie. best/worse case) scenarios
- lemonlimebitters
- Topic Author
- Offline
- Junior Member
Less
More
7 years 11 months ago #136102
by lemonlimebitters
lemonlimebitters
Randomising MaxDiff (ie. best/worse case) scenarios was created by lemonlimebitters
Hi,
Has anyone anyone done any randomisation on the MaxDiff question type ?
Limesurvey (2.0) randomisation does this to the wrong scale since the MaxDiff uses Array by column.
Has anyone anyone done any randomisation on the MaxDiff question type ?
Limesurvey (2.0) randomisation does this to the wrong scale since the MaxDiff uses Array by column.
lemonlimebitters
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
7 years 11 months ago - 7 years 11 months ago #136151
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Randomising MaxDiff (ie. best/worse case) scenarios
Here is a version of the maxDiff function updated for 2.0x. Changes to behaviour are:
- Random positioning of left/right columns
- Disabling opposite radio in a selected row (instead of pop-up alert)
Sample survey attached:
- Random positioning of left/right columns
- Disabling opposite radio in a selected row (instead of pop-up alert)
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ maxDiff({QID}); function maxDiff(qID) { // Random number between 1 and 2 // Math.floor(Math.random() * (max - min + 1)) + min; var randomNum = Math.floor(Math.random() * ((2-1)+1) + 1); // Move the cells around $('#question'+qID+' table.subquestions-list col:eq('+randomNum+')').prependTo('colgroup.col-responses'); $('#question'+qID+' table.subquestions-list thead tr:eq(0) th:eq('+(randomNum-1)+')').prependTo('#question'+qID+' table.question thead tr:eq(0)'); $('#question'+qID+' table.subquestions-list tbody tr').each(function(i){ $('td.answer-item:eq('+(randomNum-1)+')', this).prependTo(this); }); // Style stuff $('#question'+qID+' table.subquestions-list col.odd').css({ 'background-color':'transparent' }); $('#question'+qID+' table.subquestions-list tbody th').css({ 'text-align':'center' }); $('#question'+qID+' table.subquestions-list tbody tr:even td, #question'+qID+' table.question tbody tr:even th').css({ 'background-color':'#F1F1F1' }); $('#question'+qID+' table.subquestions-list tbody tr:odd td, #question'+qID+' table.question tbody tr:odd th').css({ 'background-color':'#FCFCFC' }); // Prevent clicking twice in the same row $('#question'+qID+' input.radio').on('click', function () { $('#question'+qID+' input.radio').prop('disabled', false); $('#question'+qID+' input.radio:checked').each(function(i) { var thisRow = $(this).closest('tr'); $('input.radio', thisRow).not(this).prop('disabled', true); }); }); } }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 7 years 11 months ago by tpartner.
The topic has been locked.
- lemonlimebitters
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 21
- Thank you received: 3
7 years 11 months ago #136292
by lemonlimebitters
lemonlimebitters
Replied by lemonlimebitters on topic Randomising MaxDiff (ie. best/worse case) scenarios
Thanks tpartner, I was hoping to randomise the other scale (ie. Product price, colour options, etc, in reference to your example image)
Is that possible?
Thanks for modifying to remove the pop-up
Is that possible?
Thanks for modifying to remove the pop-up
lemonlimebitters
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
7 years 11 months ago #136402
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Randomising MaxDiff (ie. best/worse case) scenarios
Oh, I see, the question randomization setting affect the answers, not the sub-questions as I thought. I'm traveling today but should have a workaround tomorrow.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3593
7 years 11 months ago #136473
by tpartner
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Randomising MaxDiff (ie. best/worse case) scenarios
Try this for randomized rows:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function(){ // Call the maxDiff() function // Set the second parameter to true for randomized rows maxDiff({QID}, true); }); function maxDiff(qID, randomize) { // Random number between 1 and 2 // Math.floor(Math.random() * (max - min + 1)) + min; var randomNum = Math.floor(Math.random() * ((2-1)+1) + 1); // Move the columns $('#question'+qID+' table.subquestions-list col:eq(1)').prependTo('colgroup.col-responses'); $('#question'+qID+' table.subquestions-list thead tr:eq(0) th:eq(0)').prependTo('#question'+qID+' table.question thead tr:eq(0)'); $('#question'+qID+' table.subquestions-list tbody tr').each(function(i){ $('td.answer-item:eq(0)', this).prependTo(this); }); $('#question'+qID+' table.subquestions-list tbody tr').each(function(i){ $('td.answer-item:eq(0)', this).prependTo(this); }); // Random rows if(randomize) { var rowsArr = []; $('#question'+qID+' table.subquestions-list tbody tr').each(function(i){ $(this).attr('data-index', i); rowsArr.push(i); }); shuffleArray(rowsArr); $(rowsArr).each(function(i){ $('#question'+qID+' table.subquestions-list tbody').append($('#question'+qID+' tr[data-index="'+this+'"]')); }); } // Style stuff $('#question'+qID+' table.subquestions-list col.odd').css({ 'background-color':'transparent' }); $('#question'+qID+' table.subquestions-list tbody th').css({ 'text-align':'center' }); $('#question'+qID+' table.subquestions-list tbody tr:even td, #question'+qID+' table.question tbody tr:even th').css({ 'background-color':'#F1F1F1' }); $('#question'+qID+' table.subquestions-list tbody tr:odd td, #question'+qID+' table.question tbody tr:odd th').css({ 'background-color':'#FCFCFC' }); // Prevent clicking twice in the same row $('#question'+qID+' input.radio').on('click', function () { $('#question'+qID+' input.radio').prop('disabled', false); $('#question'+qID+' input.radio:checked').each(function(i) { var thisRow = $(this).closest('tr'); $('input.radio', thisRow).not(this).prop('disabled', true); }); }); } function shuffleArray(array) { for (var i = array.length - 1; i > 0; i--) { var j = Math.floor(Math.random() * (i + 1)); var temp = array[i]; array[i] = array[j]; array[j] = temp; } return array; } </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The topic has been locked.