Welcome to the LimeSurvey Community Forum

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

Customized Rotation for Check box & Radio Bottom

More
1 year 4 months 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.

More
1 year 4 months ago - 1 year 4 months ago #260587 by rajkumar_dms
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: 1 year 4 months ago by rajkumar_dms.

Please Log in to join the conversation.

More
1 year 4 months ago #260845 by rajkumar_dms
Hello,
Good day

Anyone can help me on this to execute to this

Please Log in to join the conversation.

More
1 year 4 months 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.

More
1 year 4 months ago #260869 by rajkumar_dms
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.

More
1 year 4 months ago #262563 by rajkumar_dms
Hi Joffm,

Can you share the solutions for the same

Please Log in to join the conversation.

More
1 year 4 months ago #263337 by rajkumar_dms
Hi,

Anyone can you help me on this request

Please Log in to join the conversation.

More
1 year 4 months 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.

More
1 year 4 months ago #263420 by rajkumar_dms
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

Please Log in to join the conversation.

More
1 year 4 months 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.

More
1 year 4 months ago #263452 by rajkumar_dms
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.

More
1 year 4 months ago #263724 by rajkumar_dms
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.

More
1 year 3 months ago #264099 by Joffm
Hi,
I did not understand the script in the "radio" question. This is to create "Headers" in a multiple question. I removed it.

So I do not see anything here except your double codes




 

File Attachment:

File Name: limesurvey...6173.lss
File Size:52.57 KB


Joffm
 

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

Please Log in to join the conversation.

More
1 year 3 months ago #264255 by Joffm
I ask myself what is the reason for this?
Seeing the other script I assume you only want to create additional headers.
But that's much easier to achieve.
Code:
 <script type="text/javascript" charset="utf-8">
    $(document).ready(function() { 
        var SubHeading1="Header 1";
        var SubHeading2="Header 2";
        var thisQuestion = $('#question{QID}');
         // Insert sub-headings
        $('.checkbox-item:eq(0)', thisQuestion).before('<li class="inserted-sub-heading"><span class="myHeader">'+SubHeading1+'</span></li>');
        $('.checkbox-item:eq(4)', thisQuestion).before('<li class="inserted-sub-heading"><span class="myHeader">'+SubHeading2+'</span></li>');
    });
</script>
<style type="text/css">.myHeader {
    color:maroon;
    font-size:100%;
    font-weight:bold;
    background-color:#F8F8FF;
    border:1px solid #ccc;
    padding: 1px 5px;
  }
 

And in "single" questions "radio-item" instead of "checkbox-item"


And now something general:
All your questions - your bnext about the ccordinates - are obviously not related to "Installation and Update issue".
Please, use the correct section in the future

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

Please Log in to join the conversation.

Moderators: holchtpartner

Lime-years ahead

Online-surveys for every purse and purpose