Welcome to the LimeSurvey Community Forum

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

Update code for Exclusive options in Array(Number) with Checkboxes?

  • Gerard Martínez Görbig
  • Gerard Martínez Görbig's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 months 1 day ago #251519 by Gerard Martínez Görbig
Your LimeSurvey version: LimeSurvey Cloud   Version 6.3.0
==================
Hi everyone,
I have a question with an Array with checkboxes, and I want to make the last one exclusive. I found several topics in the forums relating to this, but none works. I also checked the manual and any material related.
The last code I tried is this one:

<script type="text/javascript" charset="utf-8">
    $(document).on('ready pjax:scriptcomplete',function(){
       
        var thisQuestion = $('#question{QID}')

        // Add some classes to the checkbox cells
        $('td.checkbox-item:last-child', thisQuestion).addClass('exclusive-item');
        
        // A function to un-check boxes
        function resetCheckbox(thisItem) {
            $(':hidden', thisItem).val('');
            $(':checkbox', thisItem).prop('checked', false).trigger('change');
        }
        
        // A listener on the checkboxes
        $(':checkbox', thisQuestion).on('change', function(e) {
            if($(this).is(':checked')) {
                var thisItem = $(this).closest('.answer-item');                
                var thisRow = $(this).closest('tr');
                var items = $('td.answer-item.exclusive-item', thisRow);
                if($(thisItem).hasClass('exclusive-item')) {
                    items = $('td.answer-item:not(.exclusive-item)', thisRow);
                }
                $.each(items, function(i, el) {
                    resetCheckbox(el);
                });
            }
        });
    });
</script>

Find the sample question in the file attached.

I hope someone can help. I'm not fluent in java to do any huge changes in the code. I also tried to adjust all options I could find, but still not working.
Thank you very much, 
Best
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 1 day ago #251532 by Joffm
Sorry, but I do not see any script in your lss.

And I do not see any issue if I insert the script you showed.
 

BTW: Have you the necessary rights to use javascript?

Joffm
 

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

Please Log in to join the conversation.

  • Gerard Martínez Görbig
  • Gerard Martínez Görbig's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 months 1 day ago #251540 by Gerard Martínez Görbig
Replied by Gerard Martínez Görbig on topic Update code for Exclusive options in Array(Number) with Checkboxes?
Thank you very much for your answer! Sorry, I separated the question from the survey and forgot to attach the script. Find attached one with the script pasted.
However, still does not work. Don't know why.

About the permissions, I already turned off the "Filter HTML for XSS" and the "Disable question script for XSS restricted user", and it is still not working. Is this what you are referring to?
I have other questions where I modified the script (like a Checkbox array with dropdown options), and those work perfectly.

Best,
 

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Online
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 months 1 day ago - 6 months 1 day ago #251542 by Joffm
I still do not see any script in this survey.
 

I separated the question from the survey and forgot to attach the script.

Therefore you should do it the other way.
Copy the survey, remove everything not related to your problem, send the rest as lss export.

Volunteers are not paid.
Not because they are worthless, but because they are priceless
Last edit: 6 months 1 day ago by Joffm.

Please Log in to join the conversation.

  • Gerard Martínez Görbig
  • Gerard Martínez Görbig's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 months 1 day ago #251543 by Gerard Martínez Görbig
Replied by Gerard Martínez Görbig on topic Update code for Exclusive options in Array(Number) with Checkboxes?
Hi Joffm! I just did what you asked, to do things the other way around, and I pasted the code once more. I don't know why, but now the question works fine. In any case, I have attached the sample again, but it seems that the problem is solved.
I don't know what could have happened (no idea why the code was not working, and no idea why the code wasn't exported along with the question).

Thank you very much for your help and time. I really appreciate that.
Best,
Gerard

Please Log in to join the conversation.

Lime-years ahead

Online-surveys for every purse and purpose