- Posts: 3
- Thank you received: 0
Welcome to the LimeSurvey Community Forum
Ask the community, share ideas, and connect with other LimeSurvey users!
Making Columns Exclusive - Array (Numbers) (Checkbox)
- phorcast2022
- Topic Author
- Offline
- New Member
Less
More
1 week 1 day ago #265390
by phorcast2022
Making Columns Exclusive - Array (Numbers) (Checkbox) was created by phorcast2022
Please help us help you and fill where relevant:
LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey Cloud:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey Cloud:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
LimeSurvey version: LimeSurvey Cloud Version 6.5.13
Own server or LimeSurvey Cloud: LimeSurvey Cloud
Survey theme/template: Extended from Fruity
==================
Hello,
I used the following code to make one of my question's last two rows exclusive. I was wondering if someone could help me do the same thing but instead make the last two columns exclusive, please?
Thank you!<script type="text/javascript" data-author="Tony Partner">
$(document).on('ready pjax:scriptcomplete',function(){
var thisQuestion = $('#question{QID}');
var firstRow = $('tr.subquestion-list:eq(0)', thisQuestion);
// Listener on the first row checkboxes
$(':checkbox', firstRow).on('change', function(e){
$(':checkbox', thisQuestion).prop('disabled', false);
if($(this).is(':checked')) {
var thisCell = $(this).closest('td');
var thisIndex = $(thisCell).index();
// Render this checkbox exclusive in this row
var otherRowCells = $('td.answer-item', firstRow).not(thisCell);
$(otherRowCells). each (function(i) {
$('input[type="hidden"]', this).val('');
$(':checkbox', this).prop('checked', false).trigger('change');
});
// Render this checkbox exclusive in this column
var otherColCells = $('td.answer-item:nth-child('+(thisIndex+1)+')').not(thisCell);
$(otherColCells). each (function(i) {
$('input[type="hidden"]', this).val('');
$(':checkbox', this).prop('checked', false).trigger('change').prop('disabled', true);
});
}
});
});
</script>
LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey Cloud:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
LimeSurvey version: [see right hand bottom of your LimeSurvey admin screen]
Own server or LimeSurvey Cloud:
Survey theme/template:
==================
(Write here your question/remark)Please help us help you and fill where relevant:
LimeSurvey version: LimeSurvey Cloud Version 6.5.13
Own server or LimeSurvey Cloud: LimeSurvey Cloud
Survey theme/template: Extended from Fruity
==================
Hello,
I used the following code to make one of my question's last two rows exclusive. I was wondering if someone could help me do the same thing but instead make the last two columns exclusive, please?
Thank you!<script type="text/javascript" data-author="Tony Partner">
$(document).on('ready pjax:scriptcomplete',function(){
var thisQuestion = $('#question{QID}');
var firstRow = $('tr.subquestion-list:eq(0)', thisQuestion);
// Listener on the first row checkboxes
$(':checkbox', firstRow).on('change', function(e){
$(':checkbox', thisQuestion).prop('disabled', false);
if($(this).is(':checked')) {
var thisCell = $(this).closest('td');
var thisIndex = $(thisCell).index();
// Render this checkbox exclusive in this row
var otherRowCells = $('td.answer-item', firstRow).not(thisCell);
$(otherRowCells). each (function(i) {
$('input[type="hidden"]', this).val('');
$(':checkbox', this).prop('checked', false).trigger('change');
});
// Render this checkbox exclusive in this column
var otherColCells = $('td.answer-item:nth-child('+(thisIndex+1)+')').not(thisCell);
$(otherColCells). each (function(i) {
$('input[type="hidden"]', this).val('');
$(':checkbox', this).prop('checked', false).trigger('change').prop('disabled', true);
});
}
});
});
</script>
Attachments:
Please Log in to join the conversation.
- Joffm
- Away
- LimeSurvey Community Team
Less
More
- Posts: 13217
- Thank you received: 4061
1 week 3 hours ago #265417
by Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
Replied by Joffm on topic Making Columns Exclusive - Array (Numbers) (Checkbox)
Hi,
I am sure you will find the script to make the last column exclusive many times in the forum.
As I am not very familiar with javascript I just doubled the exclusive cells with classes "exlusive-item1" and "exlusive-item2"
Joffm
I am sure you will find the script to make the last column exclusive many times in the forum.
As I am not very familiar with javascript I just doubled the exclusive cells with classes "exlusive-item1" and "exlusive-item2"
Code:
<script type="text/javascript" charset="utf-8"> $(document).ready(function() { // Call the exclude function using question ID excludeOpt({QID}); }); // A function to make the last option in each array row exclusive function excludeOpt (qID) { var thisQuestion = $('#question'+qID) // Add some classes to the checkbox cells $('td.checkbox-item', thisQuestion).addClass('normal-item'); $('tr.subquestion-list', thisQuestion).each(function(i) { $('.normal-item:last', this).removeClass('normal-item').addClass('exlusive-item1') $('.normal-item:eq(-1)', this).removeClass('normal-item').addClass('exlusive-item2') }); // A listener on the checkboxes $('input[type="checkbox"]', thisQuestion).on('change', function (event) { handleExclusive($(this).closest('td')); }); function handleExclusive(thisCell) { var thisRow = $(thisCell).closest('tr'); // Uncheck the appropriate boxes in a row if ($(thisCell).hasClass('normal-item')) { $('.exlusive-item1 input[type="checkbox"]', thisRow).prop('checked', false); $('.exlusive-item2 input[type="checkbox"]', thisRow).prop('checked', false); } else if ($(thisCell).hasClass('exlusive-item1')) { $('.exlusive-item2 input[type="checkbox"]', thisRow).prop('checked', false); $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false); } else if ($(thisCell).hasClass('exlusive-item2')) { $('.exlusive-item1 input[type="checkbox"]', thisRow).prop('checked', false); $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false); } else { $('.normal-item input[type="checkbox"]', thisRow).prop('checked', false); } // Check conditions (relevance) $('td.checkbox-item', thisRow).each(function(i) { var thisValue = ''; if($('input[type="checkbox"]', this).is(':checked')) { thisValue = 1; } var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, ''); $('input[type="hidden"]', this).attr('value', thisValue); fixnum_checkconditions(thisValue, thisSGQA, 'hidden'); }); } } </script>
Joffm
Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: DenisChenu
Please Log in to join the conversation.