I want to set checkbox after the page has renderet to the matching state of the backend.
I implemented this function for that purpose what does the job so far
Updated to user-suggestion It doesn't matter if cbs[i].dataset.thvalue or cbs[i].dataset.value
function updateCheckboxes () {
let activeCheckbox = '<input type="checkbox" onclick="handleClickOnReduce()" checked>'
let inactiveCheckbox = '<input type="checkbox" onclick="handleClickOnReduce()">'
let cbs = document.getElementsByTagName('td')
for (let i = 0; i < cbs.length; i++) {
if (cbs[i].id === 'reduceCheckbox' || cbs[i].id === 'slCheckbox') {
if (cbs[i].dataset.thvalue === 'true') {
cbs[i].innerHTML = activeCheckbox
}
else {
cbs[i].innerHTML = inactiveCheckbox
}
}
}
}
HTML part, using Thymeleaf
<td id="reduceCheckbox" data-th-value="${car.isReduced()}"></td>
<td id="slCheckbox" data-th-value="${car.isSl()}"></td>
But the browser claims by printing out the value, that it is undefined, even if the value is set as you can see in the picture live from the browser.
Due to the docu my syntax should be correct?
https://www.w3schools.com/jsref/prop_option_value.asp
Any suggestion?
Ty