How do I make a javascript function work for a series of the same components individually?

0

For example: I have this function that checks if the checkbox is checked, but it is working in general and not individually since these components are inside a table, the components are generated like this:

     var table = $('#tableproduct').DataTable();

                    results.Nfe.Produtos.forEach(function (element) {

                        var rowNode = table
                            .row.add(['<input type="checkbox" name="check" onChange="verificarCheckBox() " />',
                                element.Codigo,
                                element.Descricao,
                                '<input type="number" class="form-control " style="text-align:right; margin: 3px;" value=' + element.ValorUnitario + '  id="valor" onChange="calcular()" readonly /> ',
                                '<input type="number" class="form-control" style="text-align:right; margin: 3px;" value= ' + element.Qtd + '  id = "quantidade" readonly onChange="calcular() "/>',
                                '<input type="number" class="form-control " style="text-align:right; width: 177px; margin: 3px;"  value="0"   id="quantidade_devolvida"  readonly onChange="calcular(), verificarCheckBox()"/>',
                                '<input type = "number" class= "form-control" style = "text-align:right; margin: 3px;" value="0" id="var_qnt"  onChange="calcular()" readonly />'
                            ])
                            .draw()
                            .node();

And the function that checks the checkbox is this here:

 function verificarCheckBox() {
    var check = document.getElementsByName("check");

    for (var i = 0; i < check.length; i++) {
        if (check[i].checked == true)
        {
            document.getElementById("quantidade_devolvida").readOnly = false;
            document.getElementById("quantidade_devolvida").style.borderColor = "rgba(60, 141, 188, 0.5)";
            document.getElementById("quantidade_devolvida").style.boxShadow = "rgba(60, 141, 188, 0.77) 0px 0px 6px";
        }
        else if (check[i].checked == false)
        {
            document.getElementById("quantidade_devolvida").value = 0;
            document.getElementById("var_qnt").value = 0;
            document.getElementById("quantidade_devolvida").readOnly = true;
            document.getElementById("quantidade_devolvida").style.borderColor = "rgba(154, 154, 154, 0.51)";
            document.getElementById("quantidade_devolvida").style.boxShadow = "rgb(253, 250, 250) 0px 0px 6px";
        }
    }
}
    
asked by anonymous 22.10.2018 / 13:54

0 answers