- Posts: 14
- Thank you received: 2
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Partial Randomization Radio List - Beginner
- haroldrio
- Topic Author
- Offline
- New Member
Less
More
5 years 6 months ago #173425
by haroldrio
Partial Randomization Radio List - Beginner was created by haroldrio
Hi there.
I would like to ask for your help.
I am using limesurvey 3.xx
This is the code.
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
// The number of answers to be fixed at the end of the list
var fixedAnswers = 2;
// Set this to "true" if you want "Other" to be fixed in the last position
var otherFixed = false;
// Identify this question
var qID = {QID};
// Find the number of answers
var ansCount = $('#question'+qID+' .answer-item').length;
if($('#question'+qID+' input[type="text"]').length > 0) {
ansCount = ansCount -1
}
console.log(ansCount);
// 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^="answer"][id$="X'+qID+(ansCount-fixedIndex)+'"]');
var answerItem = $(answer).closest('.answer-item');
var answersList = $(answer).closest('ul');
$(answersList).append(answerItem);
fixedIndex--;
}
// 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>
How can I modify this code.
I have turned off my html filtering already.
answer code are in numerical order too.
// Set this to "true" if you want "Other" to be fixed in the last position
var otherFixed = false;
// Identify this question
var qID = {QID}
changed the false to true
{QID} changed to {1333}
is that correct? how about the rest?
sorry I am a total newb to coding.
I would like to ask for your help.
I am using limesurvey 3.xx
This is the code.
<script type="text/javascript" charset="utf-8">
$(document).on('ready pjax:scriptcomplete',function(){
// The number of answers to be fixed at the end of the list
var fixedAnswers = 2;
// Set this to "true" if you want "Other" to be fixed in the last position
var otherFixed = false;
// Identify this question
var qID = {QID};
// Find the number of answers
var ansCount = $('#question'+qID+' .answer-item').length;
if($('#question'+qID+' input[type="text"]').length > 0) {
ansCount = ansCount -1
}
console.log(ansCount);
// 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^="answer"][id$="X'+qID+(ansCount-fixedIndex)+'"]');
var answerItem = $(answer).closest('.answer-item');
var answersList = $(answer).closest('ul');
$(answersList).append(answerItem);
fixedIndex--;
}
// 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>
How can I modify this code.
I have turned off my html filtering already.
answer code are in numerical order too.
// Set this to "true" if you want "Other" to be fixed in the last position
var otherFixed = false;
// Identify this question
var qID = {QID}
changed the false to true
{QID} changed to {1333}
is that correct? how about the rest?
sorry I am a total newb to coding.
The following user(s) said Thank You: neraunzaran
The topic has been locked.
- haroldrio
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 2
5 years 6 months ago #173426
by haroldrio
Replied by haroldrio on topic Partial Randomization Radio List - Beginner
I would appreciate if anyone can highlight those codes that needs to be replaced and a sample for each variable.
Thank you so much.
Thank you so much.
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
5 years 6 months ago #173427
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 Partial Randomization Radio List - Beginner
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: haroldrio
The topic has been locked.
- haroldrio
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 2
5 years 6 months ago #173434
by haroldrio
Replied by haroldrio on topic Partial Randomization Radio List - Beginner
Oh My. So this is the only 3 variables that needs to be changed.
Didn't know the right QID.
Thank you so much.
Now my survey is looking cool!
Didn't know the right QID.
Thank you so much.
Now my survey is looking cool!
The topic has been locked.
- haroldrio
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 2
5 years 6 months ago #173435
by haroldrio
Replied by haroldrio on topic Partial Randomization Radio List - Beginner
Attachments:
The topic has been locked.
- tpartner
- Offline
- LimeSurvey Community Team
Less
More
- Posts: 10634
- Thank you received: 3698
5 years 6 months ago #173445
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 Partial Randomization Radio List - Beginner
You do not need to modify {QID}, that will automatically be replaced with the question ID.
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: DenisChenu
The topic has been locked.
- haroldrio
- Topic Author
- Offline
- New Member
Less
More
- Posts: 14
- Thank you received: 2
5 years 3 months ago - 4 years 9 months ago #178184
by haroldrio
Replied by haroldrio on topic Partial Randomization Radio List - Beginner
This is for my future reference.
I keep coming back to this post and forgot some few details.
Thank you so much Tpartner for the Help.
So this is the right code that worked on my Limesurvey 3.2.1
Conditions are as follows:
Global Setting - Security is set to xss OFF
Radio List
- Randomize on each page load
- No answer option is Turned OFF
- Answer Code should be sequential
- Fixed answer is only changed. (Qid is automatically changed -credits to Tpartner)
This is the code::
I keep coming back to this post and forgot some few details.
Thank you so much Tpartner for the Help.
So this is the right code that worked on my Limesurvey 3.2.1
Conditions are as follows:
Global Setting - Security is set to xss OFF
Radio List
- Randomize on each page load
- No answer option is Turned OFF
- Answer Code should be sequential
- Fixed answer is only changed. (Qid is automatically changed -credits to Tpartner)
This is the code::
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 = [color=red][b][size=5]2[/size][/b][/color]; // Identify this question var qID = {QID}; // Find the number of answers var ansCount = $('#question'+qID+' .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 answerItem = $('.answer-item[id^="javatbd"][id$="X'+qID+(ansCount-fixedIndex)+'"]'); if($('#question'+qID).hasClass('multiple-opt')) { $(answerItem).closest('.subquestion-list').append($(answerItem).parent()); } else { $(answerItem).closest('.answers-list').append(answerItem); } fixedIndex--; } }); </script>
Last edit: 4 years 9 months ago by DenisChenu. Reason: code tag
The following user(s) said Thank You: neraunzaran
The topic has been locked.
- neraunzaran
- Offline
- New Member
Less
More
- Posts: 4
- Thank you received: 0
4 years 9 months ago #185043
by neraunzaran
Replied by neraunzaran on topic Partial Randomization Radio List - Beginner
Thanks haroldio, i will keep this for future reference too.
The topic has been locked.