Gallery
BASE DE CONNAISSANCE
Share
Explore
JAVASCRIPT

CheckBox Avec question ouvert

Dans Alchemer :
image.png
Code JS :
$(document).ready(function () {
// Function to sync checkboxes between origin and target questions
function syncCheckboxes(originSelector, targetSelector) {
// Attach a change event listener to all checkboxes in the origin question
$(`${originSelector} input[type="checkbox"]`).on("change", function () {
// Get the label or aria-label of the changed checkbox
const labelText = $(this).closest("li").find("label").text().trim();
const ariaLabel = $(this).attr("aria-label");

// Find the corresponding checkbox in the target question
const targetCheckbox = $(`${targetSelector} input[type="checkbox"]`).filter(function () {
const targetLabel = $(this).closest("li").find("label").text().trim();
const targetAriaLabel = $(this).attr("aria-label");
return targetLabel === labelText || targetAriaLabel === ariaLabel;
});

// Update the checked state of the target checkbox
if (targetCheckbox.length > 0) {
targetCheckbox.prop("checked", $(this).prop("checked"));
console.log(
`Checkbox with label "${labelText}" ${
$(this).prop("checked") ? "checked" : "unchecked"
} in target question.`
);
} else {
console.warn(
`No matching checkbox found in target question for label "${labelText}".`
);
}
});
}

// Call the function to sync checkboxes
// Pass the selectors for the origin and target question containers
syncCheckboxes("#sgE-90762539-8-59-box ul.sg-list li", "#sgE-90762539-8-93-box ul.sg-list li");
});

Share
 
Want to print your doc?
This is not the way.
Try clicking the ⋯ next to your doc name or using a keyboard shortcut (
CtrlP
) instead.