mercredi 29 janvier 2020

Checkbox selection triggered from another function

I'm trying to make a code that when I click DIV, Checkbox marks me and the second time I click, it marks

The color changes and the DIV clicks. But automatic selection and unchecking for Checkbox do not work

I have error:

Uncaught TypeError: selectedValue.prop is not a function at HTMLDivElement.document.getElementById.onclick

I have template GSP with this code:

<div id="${item.key}">
    <input id="Position_${item.key}" type="checkbox" />  ${index + 1}. ${item.key} 
</div>

And script in the same file:

<script>
    document.getElementById('${item.key}').onclick = function () {
        let selectedValue = document.getElementById('Position_${item.key}');

        if (this.style.backgroundColor == 'lightgreen') {
            changeColor(this, 'white');
            selectedValue.prop('checked', false);
        } else {
            changeColor(this, 'lightgreen');
            selectedValue.prop('checked', true);
        }
    };
</script>



Aucun commentaire:

Enregistrer un commentaire