I found a solution in the community that counts the number of responses across several multiple choice questions on a page (see code below).
However when I change the alignment of the multiple choice question from the default vertical layout to column layout the solution no longer works.
Below is the code:
let all_checkboxes = document.querySelectorAll(".q-checkbox");
all_checkboxes.forEach((cb) => (cb.parentElement.onmousedown = selected_choices));
function selected_choices() {
let num_chosen = document.querySelectorAll(".q-checkbox.q-checked").length;
if (num_chosen >= 2 && !this.querySelector(".q-checked")) {
this.click();
alert(
"Please select up to two choices only. Please remove a choice before proceeding."
);
}
}
I've tried adjusting the code. I've tried inspecting the question to try and work out what has changed in the question, but I can't work it out.
1) What do I need to update in the code to make it work when the multiple choice questions are in column layout?
2) How do I find this out in the future?
Thank you
Count Multiple Choice Responses when using Column Alignment
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.

So, in the screenshot above, I clicked 5 items before it displayed the message.