- Posts: 22
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
- helviobrito
- Topic Author
- Offline
- Junior Member
Less
More
10 years 1 month ago - 10 years 1 month ago #106340
by helviobrito
Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this? was created by helviobrito
:huh: Hi fellows.
Well, I`m here again. Hope someone can help me with this issue. And sorry my bad English. I am in Brazil.
I use LimeSurvey 2.05+ Build 140302.
I have a list radio question with 3 answers: 1 - aaaa, 2 - bbbb and 3 - NoAnswer. Just options 1 and 2 must be randomized. Option 3 should be fixed at the end. But I don't want NoAnswer in all my questions, so I set to "No" the specific option in General Settings.
Searching LimeSurvey Manual, I found two Workarounds with suggested scripts to do exactly what I need. I followed all the instructions, modifying the variables filterxsshtml to FALSE and shownoanswer to 0 in config.php, as stated, set the correct IDs in JavaScript, saved it in the source of the question, but nothing worked. All the answers were randomized.
What should I do? Can anyone help me? Keep in mind, fellows, that I'm not an IT professional. I'm a research specialist, very curious and darting in the mazes of coding.
Here are the Workarounds:
Partially Randomized Answers - Multiple Options & List (radio) questions - ENHANCED </br>
Partially Randomized Answers - Multiple Options & List (radio) questions
The scripts, with my sID, gID and qID. None worked, tested with Chrome, IE 9 and Firefox 20:
Thanks.
Helvio Brito.
Well, I`m here again. Hope someone can help me with this issue. And sorry my bad English. I am in Brazil.
I use LimeSurvey 2.05+ Build 140302.
I have a list radio question with 3 answers: 1 - aaaa, 2 - bbbb and 3 - NoAnswer. Just options 1 and 2 must be randomized. Option 3 should be fixed at the end. But I don't want NoAnswer in all my questions, so I set to "No" the specific option in General Settings.
Searching LimeSurvey Manual, I found two Workarounds with suggested scripts to do exactly what I need. I followed all the instructions, modifying the variables filterxsshtml to FALSE and shownoanswer to 0 in config.php, as stated, set the correct IDs in JavaScript, saved it in the source of the question, but nothing worked. All the answers were randomized.
What should I do? Can anyone help me? Keep in mind, fellows, that I'm not an IT professional. I'm a research specialist, very curious and darting in the mazes of coding.
Here are the Workarounds:
Partially Randomized Answers - Multiple Options & List (radio) questions - ENHANCED </br>
Partially Randomized Answers - Multiple Options & List (radio) questions
The scripts, with my sID, gID and qID. None worked, tested with Chrome, IE 9 and Firefox 20:
Thanks.
Helvio Brito.
Attachments:
Last edit: 10 years 1 month ago by helviobrito.
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10095
- Thank you received: 3589
10 years 1 month ago #106355
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 Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
I think we can clean up that workaround a bit.
Assuming your answers codes are sequential numbers and you have set the answers to be randomized, adding this script to the question source will always place the last answer item at the end of the list. (you do not need to worry about the question ID - it will be automatically detected)
Here's a working survey:
Assuming your answers codes are sequential numbers and you have set the answers to be randomized, adding this script to the question source will always place the last answer item at the end of the list. (you do not need to worry about the question ID - it will be automatically detected)
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var qID = {QID}; // Find the number of answers var ansCount = $('#question'+qID+' li.answer-item').length; // Place the last answer created at the end of the list var answer = $( 'input[id$="X'+qID+ansCount+'"]'); var answerItem = $(answer).closest('li'); var answersList = $(answer).closest('ul'); $(answersList).append(answerItem); }); </script>
Here's a working survey:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
The following user(s) said Thank You: helviobrito
The topic has been locked.
- helviobrito
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 22
- Thank you received: 0
10 years 1 month ago #106369
by helviobrito
Replied by helviobrito on topic Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
Thanks a lot, tpartner.
It works perfectly.
It works perfectly.
The topic has been locked.
- helviobrito
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 22
- Thank you received: 0
10 years 1 month ago - 10 years 1 month ago #106372
by helviobrito
Replied by helviobrito on topic Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
Can I ask for more help?
If I want to set more than 1 answer to be fixed at the end of the list, what shoul I do?
e.g.:
1 - aaaa; 2 - bbbb; 3 - cccc; 4 - NoAnswer - 5 - OtherAnswer, randomizing itens 1, 2 and 3.
Thanks, again.
If I want to set more than 1 answer to be fixed at the end of the list, what shoul I do?
e.g.:
1 - aaaa; 2 - bbbb; 3 - cccc; 4 - NoAnswer - 5 - OtherAnswer, randomizing itens 1, 2 and 3.
Thanks, again.
Last edit: 10 years 1 month ago by helviobrito.
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10095
- Thank you received: 3589
10 years 1 month ago - 10 years 1 month ago #106383
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 Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
Use this script and, if necessary, modify the "fixedAnswers" variable.
Here's a working survey:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // The number of answers to be fixed at the end of the list var fixedAnswers = 2; // Identify this question var qID = {QID}; // Find the number of answers var ansCount = $('#question'+qID+' li.answer-item').length; // Place the last n answers created at the end of the list var fixedIndex = fixedAnswers - 1; for (var i=0; i<fixedAnswers; i++) { var answer = $( 'input[id$="X'+qID+(ansCount-fixedIndex)+'"]'); var answerItem = $(answer).closest('li'); var answersList = $(answer).closest('ul'); $(answersList).append(answerItem); fixedIndex--; } }); </script>
Here's a working survey:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 10 years 1 month ago by tpartner.
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10095
- Thank you received: 3589
10 years 1 month ago #106384
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 Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
I've updated the two workarounds:
Partially Randomized Answers - Multiple Options & List (radio) questions - manual.limesurvey.org/Workarounds:_Manip...28radio.29_questions
Partially Randomized Answers - Multiple Options & List (radio) questions (Enhanced) - manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29
.
Partially Randomized Answers - Multiple Options & List (radio) questions - manual.limesurvey.org/Workarounds:_Manip...28radio.29_questions
Partially Randomized Answers - Multiple Options & List (radio) questions (Enhanced) - manual.limesurvey.org/Workarounds:_Manip...tions_.28Enhanced.29
.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- helviobrito
- Topic Author
- Offline
- Junior Member
Less
More
- Posts: 22
- Thank you received: 0
10 years 1 month ago #106385
by helviobrito
Replied by helviobrito on topic Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
Thanks again and again. It's perfect.
The topic has been locked.
- LSdev
- Offline
- New Member
Less
More
- Posts: 8
- Thank you received: 3
8 years 9 months ago #121944
by LSdev
Replied by LSdev on topic Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
Thanks tpartner for updating code. Many times we have to use the codes provided by client so we can not use sequential codes.I have one suggestion here. It will helpful if you can adapt your script so that it accepts an object specifying the response code and its position. I am thinking of using function like below
Code:
fixPostions({'respondseCode1':'position1','respondseCode2':'position2'})
The topic has been locked.
- tpartner
- Away
- LimeSurvey Community Team
Less
More
- Posts: 10095
- Thank you received: 3589
8 years 9 months ago - 8 years 9 months ago #122032
by tpartner
Add this plugin to the end of template.js:
Then, call it something like this in the question source.
- Acceptable keys for the "positions" object are numeric position, "first" or "last".
- Values for the "positions" object are answer codes.
So, this example will always place answer codes A1 and A2 first and A6 last.
Sample survey:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Replied by tpartner on topic Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
That would require removing all of the specified answers from the list and then re-inserting them sequentially. Probably best done with a small jQuery pluging.It will helpful if you can adapt your script so that it accepts an object specifying the response code and its position...
Add this plugin to the end of template.js:
Code:
// A jQuery plugin to fix list-radio items in specific places // Requires a "positions" object with: // keys - numeric position, "first" or "last" // values - answer codes (function( $ ){ $.fn.lsRadioPositions = function(options) { var opts = $.extend( { positions: { } }, options); return this.each(function() { var thisQuestion = $(this); var thisID = thisQuestion.attr('id').replace(/question/, ''); var positionsArr = []; // Loop through the positions object $.each( opts.positions, function(position, code) { // Remove the option from the list $('li.answer-item[id$="X'+thisID+code+'"]').appendTo(thisQuestion); // Create an array of keys if (opts.positions.hasOwnProperty(position)) { if(position == 'first') { position = '1first'; } positionsArr.push(position); } }); positionsArr.sort(); // Loop through the positions array $.each( positionsArr, function(i) { position = this; if(position == '1first') { position = 'first'; } var thisCode = opts.positions[position] // Re-insert the option if(position == 'last') { $('ul.answers-list li.answer-item:last', thisQuestion).after($('li.answer-item[id$="X'+thisID+thisCode+'"]')); } else if(position == 1 || position == 'first') { $('ul.answers-list li.answer-item:first', thisQuestion).before($('li.answer-item[id$="X'+thisID+thisCode+'"]')); } else { $('ul.answers-list li.answer-item:eq('+(position-2)+')', thisQuestion).after($('li.answer-item[id$="X'+thisID+thisCode+'"]')); } }); }); }; })( jQuery );
Then, call it something like this in the question source.
- Acceptable keys for the "positions" object are numeric position, "first" or "last".
- Values for the "positions" object are answer codes.
So, this example will always place answer codes A1 and A2 first and A6 last.
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Apply the radioPositions plugin to this question $('#question{QID}').lsRadioPositions( { positions: { 2: 'A2', last: 'A6', first: 'A1' } } ); }); </script>
Sample survey:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Attachments:
Last edit: 8 years 9 months ago by tpartner.
The following user(s) said Thank You: LSdev
The topic has been locked.
- LSdev
- Offline
- New Member
Less
More
- Posts: 8
- Thank you received: 3
8 years 9 months ago #122046
by LSdev
Replied by LSdev on topic Help me: Partial randomized answers in LimeSurvey 2.05+ - How can I do this?
Superb as always !!!..
The topic has been locked.