Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

196
Visualizações
Checkbox checked, javascript in Django template

I am just trying to display hiddens items in django template when checkbox is checked, but in my console i am getting

1:194 Uncaught TypeError: Cannot read properties of null (reading 'checked')
    at inventoryFunction (1:194:22)
    at HTMLInputElement.onclick (1:107:73)

the items are hidden in a table and when i check a category i am hoping to get them displayed here is the template :

<div class="inventory-content">
    <div class='category'>
        <div>Categories</div>
        <div class='category-checkbox'>
            {%for category in categories%}
            <input type="checkbox" id="{{category.id}}" onclick="inventoryFunction()">
            <label for="{{category.id}}"> {{category.name}}</label><br>
            {%endfor%}
        </div>
    </div>
    <div class='items'>
        {% for category in items%}
        <div class='{{category.id}}' style="display:none">
            <div>{{category}}</div>
            <table class='runninghours-table'>
                <tr>
                    <th>Item name</th>
                    <th>part number</th>
                    <th>R.O.B</th>
                </tr>
                <tbody>
                    {%for item in category.items.all%}
                    <tr>
                        <td>{{item.name}}</td>
                        <td>{{item.part_number}}</td>
                        <td>{{item.ROB}}</td>
                    </tr>
                    {%endfor%}
                    </tobdy>
            </table>
        </div>
        {%endfor%}
    </div>

</div>

the JavaScript :

<script>
    function inventoryFunction() {
        var checkBox = document.getElementById("{{category.id}}");
        var item = document.getElementsByClassName("{{category.id}}");
        if (checkBox.checked == true) {
            item.style.display = "block";
        } else {
            item.style.display = "none";
        }
    }
</script>
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda