Verification return is sent three times

Asked

Viewed 17 times

-1

By clicking the button, run this code down

It was to generate only one position of the array. In this case it is generated 3 positions, as if there had been 3 tests

$(document).on('click','#btnSegundaEtapa',function () {

    var arrayObjCat1 = [];

    $(".form-group").find('*').each(function(){
        var id = $(this).attr("id");

        if($(this).is(':checked')){
            if ( $("input[type='radio'][name='Licenciamentodeusuários']").is(':checked') ) {
                className = $("#"+id).data('class-name');
                vlrUnitario = $("."+className).text();

                vlrUnitario = vlrUnitario.replace("$","");
                vlrUnitario = parseFloat(vlrUnitario.replace(',','.'));
                arrayObjCat1.push({part_number:$('#'+id).data('part-number'), nome_item:$('#'+id).data('nome-item'),qtde:$('#'+id).val(),preco_unitario:vlrUnitario});
                console.log(arrayObjCat1);
            }


         }
     })

});

And this comeback happens inserir a descrição da imagem aqui inserir a descrição da imagem aqui

  • Consider explaining your problem better

  • I pressed to publish unintentionally, look if it became clearer

  • Gabriel, what is the question or what is not working as you want?

  • I want this data to be executed only once and not 3 times

  • 1

    You are running console.log within the function each, this means it will print on the console each time it passes the loop. Try to put the console out of the loop that will print only once.

  • You have $(".form-group").find('*').each( this will make the code run over and over again...

  • But it generates an array of 3 positions, which I don’t want

Show 2 more comments

1 answer

0

$(document).on('click','#btnSegundaEtapa',function () {

    var arrayObjCat1 = [];

    $(".form-group").find('*').each(function(){
        var id = $(this).attr("id");

        if($(this).is(':checked')){
            if ( $("input[type='radio'][name='"+id+"']").is(':checked') ) {
                className = $("#"+id).data('class-name');
                vlrUnitario = $("."+className).text();

                vlrUnitario = vlrUnitario.replace("$","");
                vlrUnitario = parseFloat(vlrUnitario.replace(',','.'));
                arrayObjCat1.push({part_number:$('#'+id).data('part-number'), nome_item:$('#'+id).data('nome-item'),qtde:$('#'+id).val(),preco_unitario:vlrUnitario});
                console.log(arrayObjCat1);
            }


         }
     })

});

the above code solved my problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.