Translating the answer from here(adapted):
+ "<td>" + "<input type='checkbox' class='link-check' onchange="cbChange(this)" />" + "</td>"
// ...
function cbChange(obj) {
var cbs = document.getElementsByClassName("link-check");
for (var i = 0; i < cbs.length; i++) {
if(cbs[i] !== obj) cbs[i].checked = false;
}
}
Basically, what was done was the following: The function takes all checkboxes with the 'link-check' class, and puts them in the cbs array. Iterate on all of them, uncheck all of them, and then mark just the one that was clicked. Then add this function in an onchange event to all checkboxes so it works on all of them.
I hope it helps.
Have you tried warpar the table in a form and use a radio button instead of a checkbox?
– Máttheus Spoo
I didn’t try, how can I?
– Mariana
Place the table inside a form tag, like any form, and use radio Buttons instead of checkbox. He does exactly that, when you score one, the other skips.
– Máttheus Spoo
https://www.w3schools.com/html/html_forms.asp if you have any doubts about how to implement, but it is extremely simple. Edit: actually, from what I’m seeing here, you don’t even have to put in a form, just put the same "name" on all the radio Buttons that they’re linked to, so when you mark each other uncheck.
– Máttheus Spoo
It was requested by checkbox, because of aesthetics, in case the function is not possible, I will try this way.
– Mariana
It’s possible, it’s just more work. I’ll check here and I’ll answer you, if no one answers before.
– Máttheus Spoo
https://stackoverflow.com/questions/19362284/uncheck-a-checkbox-if-another-checked-with-javascript .
– Máttheus Spoo
You can use radio Buttons as already suggested, think about the functionality. The aesthetic question you can change with CSS to do the radio look like a checkbox.
– Renan Gomes