- Posts: 18
- Thank you received: 4
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Answers random order - partial randomization & keeping distinct answers fixed
- TonisOrmisson
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
10 years 7 months ago #99873
by TonisOrmisson
Answers random order - partial randomization & keeping distinct answers fixed was created by TonisOrmisson
I would need to randomize part of the answers and keep some answers at a fixed position.
A typical example - a simple radio question that needs most of the answers randomized, but would need to have a "do not know" fixed at the bottom.
Any ideas how to do that?
I am currently considering renaming "no answer" to "don't know" in the translation.
Alternatively I could have some script rewriting the answers sortorder value on each pageload. Probably some security issues here going directly to edit databases.
Any ways to reorder distinct answers by javascript on display?
I am using multiple versions (eg. 1.92+ and the 2.00)
A typical example - a simple radio question that needs most of the answers randomized, but would need to have a "do not know" fixed at the bottom.
Any ideas how to do that?
I am currently considering renaming "no answer" to "don't know" in the translation.
Alternatively I could have some script rewriting the answers sortorder value on each pageload. Probably some security issues here going directly to edit databases.
Any ways to reorder distinct answers by javascript on display?
I am using multiple versions (eg. 1.92+ and the 2.00)
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
10 years 7 months ago #99877
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 Answers random order - partial randomization & keeping distinct answers fixed
Have a look at this workaround -
manual.limesurvey.org/Workarounds:_Manip...28radio.29_questions
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
- TonisOrmisson
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 18
- Thank you received: 4
10 years 7 months ago #99883
by TonisOrmisson
Replied by TonisOrmisson on topic Answers random order - partial randomization & keeping distinct answers fixed
exactly what I was looking for.
excellent, thanks!
I did google for some time to find that but without luck. Thanks again.
excellent, thanks!
I did google for some time to find that but without luck. Thanks again.
The topic has been locked.
- TonisOrmisson
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 18
- Thank you received: 4
10 years 7 months ago #99887
by TonisOrmisson
Replied by TonisOrmisson on topic Answers random order - partial randomization & keeping distinct answers fixed
have some problems implementing.
I got the "Partially Randomized Answers - Multiple Options & List (radio) questions" working
didn't work on my custom old template, but worked on default
but I can not get the "Partially Randomized Answers - Multiple Options & List (radio) questions - ENHANCED" version working (the one with multiple fixed items).
working with 1.92 build 10859.
Could anybody show a working set-up for the enhanced version??
I got the "Partially Randomized Answers - Multiple Options & List (radio) questions" working
didn't work on my custom old template, but worked on default
but I can not get the "Partially Randomized Answers - Multiple Options & List (radio) questions - ENHANCED" version working (the one with multiple fixed items).
working with 1.92 build 10859.
Could anybody show a working set-up for the enhanced version??
The topic has been locked.
- TonisOrmisson
- Topic Author
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 18
- Thank you received: 4
10 years 7 months ago #99908
by TonisOrmisson
Replied by TonisOrmisson on topic Answers random order - partial randomization & keeping distinct answers fixed
found the problem
with the enhanced versiosn you should not set the random_order attribute to 1
The randomization is done with javascript. I set the random_order to 0 and it works in all versions i have now.
so as far as I understand there is a misleading manual - this should not be done with the enhanced version:
"Set the random_order question attribute to 1."
with the enhanced versiosn you should not set the random_order attribute to 1
The randomization is done with javascript. I set the random_order to 0 and it works in all versions i have now.
so as far as I understand there is a misleading manual - this should not be done with the enhanced version:
"Set the random_order question attribute to 1."
The topic has been locked.
- LloydW
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
10 years 3 months ago #103531
by LloydW
Replied by LloydW on topic Answers random order - partial randomization & keeping distinct answers fixed
Similar sort of question but for an array.
I want to randomise all the subquestions, but I want to hold the last one (which is different from the rest) at the end of the list (but not an exclusive answer like 'none of the above').
Haven't been able to get most of the solutions I've found on-line to work. The question example is attached & using Limesurvey 2.05.
Regards, Lloyd.
I want to randomise all the subquestions, but I want to hold the last one (which is different from the rest) at the end of the list (but not an exclusive answer like 'none of the above').
Haven't been able to get most of the solutions I've found on-line to work. The question example is attached & using Limesurvey 2.05.
Regards, Lloyd.
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
10 years 3 months ago #103551
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 Answers random order - partial randomization & keeping distinct answers fixed
Lloyd, since your sub-question codes all start with an alpha character (as they should) and are sequential, we can detect the highest code (alphabetically) and move that sub-question to the end.
Add the following to the array question source:
.
Add the following to the array question source:
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question ID var qID = {QID}; // Build an array of subquestion codes var sqCodeArr = new Array(); $('#question'+qID+' table.question tbody tr').each(function(i) { var sqCode = $(this).attr('id').split('X'+qID+'')[1]; sqCodeArr.push(sqCode); }); // Find the highest code (alphabetically) sqCodeArr.sort(); var highCode = sqCodeArr[sqCodeArr.length-1]; // Now, move that subquestion to the bottom $('#question'+qID+' table.question tbody').append($('#question'+qID+' tr[id$="X'+qID+highCode+'"]')); }); </script>
.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: LloydW
The topic has been locked.
- LloydW
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 0
10 years 3 months ago #103571
by LloydW
Replied by LloydW on topic Answers random order - partial randomization & keeping distinct answers fixed
A super solution and well coded and explained - thanks Tony it works a charm.
Many thanks.
Many thanks.
The topic has been locked.
- dknvs
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
9 years 10 months ago #109726
by dknvs
Replied by dknvs on topic Answers random order - partial randomization & keeping distinct answers fixed
Hi,
I have found the following [url=http://http://manual.limesurvey.org/Workarounds:_Manipulating_a_survey_at_runtime_using_Javascript#Partially_Randomized_Answers_-_Multiple_Options_.26_List_.28radio.29_questions]script[/url] that helps me the make the last answer choice fixed.
However, it's only for codes that are in order. For example:
1 answer1
2 answer2
3 answer3
For our survey, we don't want to include "don't know" in the calculation. So we usually give DK as the don't know/none of above.
1 answer1
2 answer2
3 answer3
DK None of above
The following javascript will only work if we make DK a "4". Could you help me to this?
thank you!
<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>
I have found the following [url=http://http://manual.limesurvey.org/Workarounds:_Manipulating_a_survey_at_runtime_using_Javascript#Partially_Randomized_Answers_-_Multiple_Options_.26_List_.28radio.29_questions]script[/url] that helps me the make the last answer choice fixed.
However, it's only for codes that are in order. For example:
1 answer1
2 answer2
3 answer3
For our survey, we don't want to include "don't know" in the calculation. So we usually give DK as the don't know/none of above.
1 answer1
2 answer2
3 answer3
DK None of above
The following javascript will only work if we make DK a "4". Could you help me to this?
thank you!
<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>
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10099
- Thank you received: 3589
9 years 10 months ago - 9 years 10 months ago #109736
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 Answers random order - partial randomization & keeping distinct answers fixed
Try this
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Identify this question var qID = {QID}; // Place the "DK" code option at the end of the list var answer = $( 'input[id$="X'+qID+'DK"]'); var answerItem = $(answer).closest('li'); var answersList = $(answer).closest('ul'); $(answersList).append(answerItem); }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 9 years 10 months ago by tpartner.
The following user(s) said Thank You: dknvs
The topic has been locked.
- dknvs
- Offline
- New Member
Less
More
- Posts: 12
- Thank you received: 0
9 years 10 months ago #109758
by dknvs
Replied by dknvs on topic Answers random order - partial randomization & keeping distinct answers fixed
YAY! IT WORKS! THANK YOU SO MUCH! :woohoo:
The topic has been locked.
- delarammahdaviii
- Offline
- Senior Member
Less
More
- Posts: 57
- Thank you received: 3
8 years 3 months ago #129711
by delarammahdaviii
Replied by delarammahdaviii on topic Answers random order - partial randomization & keeping distinct answers fixed
help me about ,Array questions to be randomized while always keeping 3 sub-question at the end
The topic has been locked.