Why is this function interpreting that it hears more than one click?

Asked

Viewed 36 times

0

I have the following function.

function getValue() {
    $("#SavePaper").click(function(e) {
        if($(this).is(':checked')){
            if ( $("input[type='radio'][name='Licenciamentodeusuários']").is(':checked') ){
                valor = $('input:radio[name=Licenciamentodeusuários]:checked').val();

                if(valor == "Até") {

                    if ($("#Ate-Comercial-MF").val() != undefined) {
                        qtdUsuarios = $("#Até-Comercial-MF").val();
                        vlrSavePaper = qtdUsuarios * 0.99;
                        console.log(vlrSavePaper);
                    }
                    if ($("#Até-Educacional-MF").val() != undefined) {
                        qtdUsuarios = $("#Até-Educacional-MF").val();
                        vlrSavePaper = qtdUsuarios * 0.99;
                        console.log(vlrSavePaper);
                    }
                    if ($("#Até-Profissional-MF").val() != undefined) {
                        qtdUsuarios = $("#Até-Profissional-MF").val();
                        vlrSavePaper = qtdUsuarios * 0.99;
                        console.log(vlrSavePaper);
                    }

                    if ($("#Até-Comercial-NG").val() != undefined) {
                        qtdUsuarios = $("#Até-Comercial-NG").val();
                        vlrSavePaper = qtdUsuarios * 0.99;
                        console.log(vlrSavePaper);
                    }
                    if ($("#Até-Educacional-NG").val() != undefined) {
                        qtdUsuarios = $("#Até-Educacional-NG").val();
                        vlrSavePaper = qtdUsuarios * 0.20;
                        console.log(vlrSavePaper);
                    }
                    if ($("#Até-Profissional-NG").val() != undefined) {
                        qtdUsuarios = $("#Até-Profissional-NG").val();
                        vlrSavePaper = qtdUsuarios * 0.99;
                        console.log(vlrSavePaper);
                    }
                }else{
                    valor = valor.replace(/\s{2,}/g, ' ');
                    valor = valor.split(" ");

                    vlrSavePaper = valor[2] * 0.99;
                    console.log(vlrSavePaper);
                }
            }

         }
     });
}

This function is an onclick() call from a checkbox, and it looks like it’s running as if it were several clicks, by my Chrome debugging understanding.

This is the return in Chrome

With 1 click inserir a descrição da imagem aqui inserir a descrição da imagem aqui With 2 clicks inserir a descrição da imagem aqui inserir a descrição da imagem aqui 3 clicks inserir a descrição da imagem aqui inserir a descrição da imagem aqui

  • In the code you put in the question, which is line 59?

  • is the console.log of Until-Commercial-NG

  • In his js-proposta-comercial.js what’s on line 59?

  • console.log(vlrSavePaper); That

  • If you call the function getValue three times, you will associate the function in the event click to checkbox three times. Food for thought.

  • What do you mean calling it three times?

  • I understood it... it would end up not affecting the final value I believe

Show 2 more comments
No answers

Browser other questions tagged

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