Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Customized Rotation for Check box & Radio Bottom

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 months 2 days ago #260585 by rajkumar_dms
Please help us help you and fill where relevant:
Your LimeSurvey version: 6.5
Own server or LimeSurvey hosting:Clould
Survey theme/template:
==================
Hello Team,
We are the great!
I would like the Rotation in radio bottom & check box type question with some codes are not be part of rotation and that code will placed in their original place
For Example i had Q1 having option 1 to 9 then i would like to Rotate the option but code 2,5,8 would not be rotate and these code are to be shown their respectively position

Please Log in to join the conversation.

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
7 months 2 days ago - 7 months 2 days ago #260587 by rajkumar_dms
Replied by rajkumar_dms on topic Customized Rotation for Check box & Radio Bottom
I am wondering where is the error in this script
<script type="text/javascript" charset="utf-8">

$(document).on('ready pjax:scriptcomplete',function(){

// Define the answers to be fixed at specific positions
var fixedAnswers = [2,4,6]

// Identify this question
var qID = {QID};

// Move fixed answers to their respective positions
fixedAnswers.forEach(function(fixedAnswer) {
var answer = $('input[id^="answer"][id$="X'+ qID + fixedAnswer +'"]');
var answerItem = $(answer).closest('.answer-item');
var answersList = $(answer).closest('ul');
var targetPosition = fixedAnswer.position - 1; // Adjust position for zero-based index
$(answersList).find('.answer-item').eq(targetPosition).before(answerItem);
});

});
</script>
Last edit: 7 months 2 days ago by rajkumar_dms.

Please Log in to join the conversation.

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 months 4 weeks ago #260845 by rajkumar_dms
Replied by rajkumar_dms on topic Customized Rotation for Check box & Radio Bottom
Hello,
Good day

Anyone can help me on this to execute to this

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 4 weeks ago #260867 by Joffm
Please, do not try to push again if you do not get an answer over the weekend
We do this work in our spare time on a voluntary base.

If you do not have time you should contact one of the LimeSurvey partners for professional support.
[url] www.limesurvey.com/ [/url]
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 months 4 weeks ago #260869 by rajkumar_dms
Replied by rajkumar_dms on topic Customized Rotation for Check box & Radio Bottom
Joffm@ Sorry for inconvenienced caused by me
i will not push for if i didn't the answer
i will keep the patience for the same

Please Log in to join the conversation.

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 months 3 weeks ago #262563 by rajkumar_dms
Replied by rajkumar_dms on topic Customized Rotation for Check box & Radio Bottom
Hi Joffm,

Can you share the solutions for the same

Please Log in to join the conversation.

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 months 2 weeks ago #263337 by rajkumar_dms
Replied by rajkumar_dms on topic Customized Rotation for Check box & Radio Bottom
Hi,

Anyone can you help me on this request

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 2 weeks ago #263338 by Joffm
You can adapt this (of course without removing certain checkboxes)
[url] forums.limesurvey.org/forum/can-i-do-thi...-random-items#263207 [/url]
One array with your random codes.
Shuffle it
Insert your "fixed" codes at the resp. places (javascript function "splice")
[url] www.w3schools.com/jsref/jsref_splice.asp [/url]

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 months 1 week ago #263420 by rajkumar_dms
Replied by rajkumar_dms on topic Customized Rotation for Check box & Radio Bottom
I had adapt that unable to make that
here is the java script for the same
<script type="text/javascript" charset="utf-8">
/ Wait for the LimeSurvey page to fully load
$(document).on('ready pjax:scriptcomplete',function(){
// Identify the question container
var questionContainer = $('#question{QID}');

// Find all the checkboxes within the question container
var checkboxes = questionContainer.find('input[type="checkbox"]');

// Filter out the fixed checkboxes (2 and 5) and store their values
var fixedCheckboxes = ;
checkboxes.each(function() {
var checkbox = $(this);
var checkboxValue = parseInt(checkbox.val());
if (checkboxValue === 2 || checkboxValue === 5) {
fixedCheckboxes.push(checkbox);
}
});

// Remove the fixed checkboxes from the list
checkboxes = checkboxes.not(fixedCheckboxes);

// Shuffle the remaining checkboxes
checkboxes.sort(function() { return Math.random() - 0.5; });

// Insert the fixed checkboxes at their respective positions
questionContainer.find('input[type="checkbox"]').slice(0, 0).before(fixedCheckboxes[0]);
questionContainer.find('input[type="checkbox"]').slice(3, 3).before(fixedCheckboxes[1]);
});
</script>

Also attached the lss file for the same
Attachments:

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Away
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 1 week ago #263427 by Joffm
Sorry, but where did you find this code?
Code:
var questionContainer = $('#question{QID}');
 
// Find all the checkboxes within the question container
var checkboxes = questionContainer.find('input[type="checkbox"]');
 
// Filter out the fixed checkboxes (2 and 5) and store their values
var fixedCheckboxes = ;
checkboxes.each(function() {
var checkbox = $(this);
var checkboxValue = parseInt(checkbox.val());
if (checkboxValue === 2 || checkboxValue === 5) {
fixedCheckboxes.push(checkbox);
}
});
 
// Remove the fixed checkboxes from the list
checkboxes = checkboxes.not(fixedCheckboxes);
 
// Shuffle the remaining checkboxes
checkboxes.sort(function() { return Math.random() - 0.5; });
 
// Insert the fixed checkboxes at their respective positions
questionContainer.find('input[type="checkbox"]').slice(0, 0).before(fixedCheckboxes[0]);
questionContainer.find('input[type="checkbox"]').slice(3, 3).before(fixedCheckboxes[1]);

which is absolutely different from what is in the linked thread
[url] forums.limesurvey.org/forum/can-i-do-thi...-random-items#263207 [/url]
Why didn't you use this?

Here you see three arrays. 
You only use one array with your random codes. (arr1)
Shuffle it.
Insert your "fixed" codes at the resp. places (javascript function "splice")
No randomization, no concatination
Just store into your question of type "short text"
$('input:text', thisQuestion).val(arr1);
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 months 1 week ago #263452 by rajkumar_dms
Replied by rajkumar_dms on topic Customized Rotation for Check box & Radio Bottom
Thanks for explanation
I had tried it but i am wondering it's not working as per need
Seems i missed something
Can look on it and i have attached the lss file for the same

Thanks

Please Log in to join the conversation.

  • rajkumar_dms
  • rajkumar_dms's Avatar Topic Author
  • Offline
  • Premium Member
  • Premium Member
More
6 months 1 week ago #263724 by rajkumar_dms
Replied by rajkumar_dms on topic Customized Rotation for Check box & Radio Bottom
Thanks for explanation
I had tried it but i am wondering it's not working as per need
Seems i missed something
Can look on it and i have attached the lss file for the same

Thanks

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose