Of course, and I'm sorry if you saw my message as a lack of respect or consideration for your work. On the contrary, your help (and that of tpartner and DenisChenu) is greatly appreciated. From my past experiences on the forum (which is small), either the answer arrives quickly, or it doesn't. So I preferred to post again because of the short deadline imposed on me at work. Please accept my apologies.
So thank you very much for your reply and I'll see if I can find the solution with these indications using chatgpt. I have virtually no skills with this language so the latter could help.
Thanks again!
David
EDIT : with a couple of back and forth with ChatGPT and using tpartner's code and your input, I ended up with the following code, that seems to do what I want
Code:
<script type="text/javascript" data-author="DBEL">
$(document).ready(function() {
// Call the exclude function using question ID
excludeOpt({QID});
});
// A function to set up exclusivity
function excludeOpt(qID) {
var thisQuestion = $('#question' + qID);
// Set up exclusivity for each row
thisQuestion.find('tr.subquestion-list').each(function() {
setupRowExclusivity($(this));
});
// A listener on the checkboxes
thisQuestion.find('input[type="checkbox"]').on('change', function(event) {
handleExclusive($(this));
});
function setupRowExclusivity(row) {
row.find('td.checkbox-item').each(function(index) {
if (index === 1) {
$(this).addClass('exclusive-item');
} else if (index === 0) {
$(this).addClass('neutral-item');
} else {
$(this).addClass('normal-item');
}
});
$('.exclusive-item input[type="hidden"]', row).val('');
// Initially disable the normal items
$('.normal-item input[type="checkbox"]', row).prop('disabled', true);
}
function handleExclusive(thisInput) {
var thisCell = thisInput.closest('td');
var thisRow = thisInput.closest('tr');
if ($(thisCell).hasClass('neutral-item')) {
// Do nothing or add specific logic for the neutral item
} else if ($(thisCell).hasClass('exclusive-item')) {
// If exclusive item is checked, enable/disable normal items accordingly
var normalItems = $('.normal-item input[type="checkbox"]', thisRow);
normalItems.prop('disabled', !thisInput.is(':checked'));
if (!thisInput.is(':checked')) {
normalItems.prop('checked', false);
}
}
// Check conditions (relevance)
$('td.checkbox-item', thisRow).each(function() {
var thisValue = $('input[type="checkbox"]', this).is(':checked') ? 1 : '';
var thisSGQA = $('input[type="checkbox"]', this).attr('id').replace(/cbox_/, '');
$('input[type="hidden"]', this).attr('value', thisValue);
fixnum_checkconditions(thisValue, thisSGQA, 'hidden');
});
}
}
</script>