- Posts: 114
- Thank you received: 1
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Fixed the answeat the end and the top
- RitaShen
- Topic Author
- Offline
- Premium Member
Less
More
4 months 1 week ago #253617
by RitaShen
Fixed the answeat the end and the top was created by RitaShen
Please help us help you and fill where relevant:
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting: 5.6.49
Survey theme/template:LimeSurvey Bootwatch Theme
==================
Hi there,
I know that there is already a script to fix the last answer option when randomizing it.
Does anyone of you know could we / how to fix the answer at the end and the top at the same time?
for example,
1(fixed)
3
2
4
5(fixed)
1(fixed)
2
4
3
5(fixed)
Thank you very much!
Your LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey hosting: 5.6.49
Survey theme/template:LimeSurvey Bootwatch Theme
==================
Hi there,
I know that there is already a script to fix the last answer option when randomizing it.
Does anyone of you know could we / how to fix the answer at the end and the top at the same time?
for example,
1(fixed)
3
2
4
5(fixed)
1(fixed)
2
4
3
5(fixed)
Thank you very much!
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
4 months 1 week ago #253624
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 Fixed the answeat the end and the top
What question type? Can you attach a small sample survey (.lss file) containing only the relevant questions?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- RitaShen
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 114
- Thank you received: 1
4 months 1 week ago #253631
by RitaShen
Replied by RitaShen on topic Fixed the answeat the end and the top
Dear tpartner,
many thanks, I just attached a sample survey,
In the question, E & F have already been fixed at the end.
Now, I want A to be fixed at the top of options
many thanks, I just attached a sample survey,
In the question, E & F have already been fixed at the end.
Now, I want A to be fixed at the top of options
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
4 months 1 week ago - 4 months 5 days ago #253642
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 Fixed the answeat the end and the top
This script, in the question source of a list-radio question, will fix the answer codes defined in the fixedStartCodes variable to the start of the answers list and the codes in the fixedEndCodes variable to the end of the list.
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // The answer codes of item(s) to be fixed var fixedStartCodes = [1]; var fixedEndCodes = [4,5,6]; // Set this to "true" if you want "Other" to be fixed in the last position var otherFixed = false; // Identify this question var qID = '{QID}'; var thisQuestion = $('#question'+qID); // Fix the item(s) to the start $.each(fixedStartCodes, function(i, code) { $('.answer-item[id$="X'+qID+code+'"]').prependTo($('.answers-list ul:eq(0)', thisQuestion)); }); // Fix the item(s) to the end $.each(fixedEndCodes, function(i, code) { $('.answer-item[id$="X'+qID+code+'"]').appendTo($('.answers-list ul:eq(0)', thisQuestion)); }); // Handle "Other" if(otherFixed == true && $('#question'+qID+' input[type="text"]').length > 0) { var otherAnswer = $('#question'+qID+' input[type="text"]'); var otherAnswerItem = $(otherAnswer ).closest('.answer-item'); var otherAnswersList = $(otherAnswer ).closest('ul'); $(otherAnswersList).append(otherAnswerItem); } }); </script>
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 4 months 5 days ago by tpartner. Reason: Update code
Please Log in to join the conversation.
- RitaShen
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 114
- Thank you received: 1
4 months 1 week ago #253672
by RitaShen
Replied by RitaShen on topic Fixed the answeat the end and the top
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
4 months 1 week ago #253720
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 Fixed the answeat the end and the top
Did you try the attached sample survey?
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- RitaShen
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 114
- Thank you received: 1
4 months 1 week ago #253722
by RitaShen
Replied by RitaShen on topic Fixed the answeat the end and the top
I sincerely apologize. I do recall that it was supposed to be included, but I might have inserted it before sending it out.
The following is an attachment
The following is an attachment
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
4 months 1 week ago #253723
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 Fixed the answeat the end and the top
Did you try my sample survey.
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.
- RitaShen
- Topic Author
- Offline
- Premium Member
Less
More
- Posts: 114
- Thank you received: 1
4 months 1 week ago #253724
by RitaShen
Replied by RitaShen on topic Fixed the answeat the end and the top
yes I've tried your sample survey, and it can work,
I directly copied the syntax directly from the sample survey and adjusted // The answer codes of item(s) to be fixed
var fixedStartCodes = [1];
var fixedEndCodes = [4, 5, 6];
Due to this question having conditional settings, I am unsure if this will have any implications.
I directly copied the syntax directly from the sample survey and adjusted // The answer codes of item(s) to be fixed
var fixedStartCodes = [1];
var fixedEndCodes = [4, 5, 6];
Due to this question having conditional settings, I am unsure if this will have any implications.
Please Log in to join the conversation.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10109
- Thank you received: 3595
4 months 5 days ago #253816
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 Fixed the answeat the end and the top
This will handle multiple instances on a page:
Sample survey attached:
Code:
<script type="text/javascript" data-author="Tony Partner"> $(document).on('ready pjax:scriptcomplete',function(){ // The answer codes of item(s) to be fixed var fixedStartCodes = [1]; var fixedEndCodes = [4,5,6]; // Set this to "true" if you want "Other" to be fixed in the last position var otherFixed = false; // Identify this question var qID = '{QID}'; var thisQuestion = $('#question'+qID); // Fix the item(s) to the start $.each(fixedStartCodes, function(i, code) { $('.answer-item[id$="X'+qID+code+'"]').prependTo($('.answers-list ul:eq(0)', thisQuestion)); }); // Fix the item(s) to the end $.each(fixedEndCodes, function(i, code) { $('.answer-item[id$="X'+qID+code+'"]').appendTo($('.answers-list ul:eq(0)', thisQuestion)); }); // Handle "Other" if(otherFixed == true && $('#question'+qID+' input[type="text"]').length > 0) { var otherAnswer = $('#question'+qID+' input[type="text"]'); var otherAnswerItem = $(otherAnswer ).closest('.answer-item'); var otherAnswersList = $(otherAnswer ).closest('ul'); $(otherAnswersList).append(otherAnswerItem); } }); </script>
Sample survey attached:
Cheers,
Tony Partner
Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Please Log in to join the conversation.