Empty string passed to getElementById ()

1

I'm using jQuery and I have the following code

jQuery(document).ready(function($){

      $(".checkParcelamento").click(function(){
          var bandeira = $("#bandeiraCartao").val();
          var numero_cartao = $("input[name='numero_cartao']").val();
          var cvv = $("input[name='cvv']").val();
          var mes_cartao = $("input[name='mes_cartao']").val();
          var ano_cartao = $("input[name='ano_cartao']").val();

          if(numero_cartao == ''){

            swal('Erro!', 'Por favor, informe o número do seu cartão para continuar', 'error');

          }else if(cvv == ''){

            swal('Erro!', 'Por favor, informe o código de segurança para continuar', 'error');

          }else if(mes_cartao == ''){

            swal('Erro!', 'Por favor, informe o mês da validade para continuar', 'error');

          }else if(ano_cartao == ''){

            swal('Erro!', 'Por favor, informe o ano da validade para continuar', 'error');

          }else{


            $gn.ready(function(checkout) {

            var callback = function(error, response) {
              if(error) {
                // Trata o erro ocorrido
                console.error(error);
              } else {

                checkout.getInstallments(50000,bandeira, function(error2, response2){
                  if(error2) {
                    // Trata o erro ocorrido
                    console.log(error2);
                  } else {

                    console.log(response2);

                    $.each(response2, function(i,e){

                    $.each(e, function(a,b){

                      if(a == 'installments'){

                        var html = '<select name="parcelamento" class="form-control">';

                        $.each(b, function(c,d){

                          html += '<option value="'+d.currency+'">'+d.installment+'x de '+d.currency+'</option>';

                        });

                        html += '</select>';

                        $("#parcelamento").html(html);

                      }
                    });
                  });
                  }
                });
                // Trata a resposta
                console.log(response);
              }
            };

            checkout.getPaymentToken({
              brand: bandeira, // bandeira do cartão
              number: numero_cartao, // número do cartão
              cvv: cvv, // código de segurança
              expiration_month: mes_cartao, // mês de vencimento
              expiration_year: ano_cartao // ano de vencimento
            }, callback);

          });


          }
      });
    });

The problem occurs in the line $ (".prepareParcelamento"). click (function () {. When I click the button, instead of executing the code, it returns me the error String vazia passada para getElementById() that it gives in the jQuery file.

Strange is that I have other code that does click normally, but it's not working. The button code:

<div class="form-group">
<input type="button" id="checkParcelamento" class="btn btn-primary checkParcelamento" value="Continuar">
</div>

I have tried using # but the same error occurs.

    
asked by anonymous 19.10.2016 / 04:40

3 answers

1

I believe that jQuery might have a deprivation with some other browser features when it interprets the query of the first parameter of $(query) - > jQuery(query) - > $.fn.find(query) , etc., for example, maybe jQuery needs to find out whether the query forms HTML elements, for example:

$("<span></span>")

Mozilla Firefox may have a native method that works differently from other browsers, maybe jQuery depends on this native method, so some confusion occurs and jQuery ends up passing a string empty to document.getElementById . Another exception possibility can be (very, very) rarely caused by a browser extension.

Note: this Empty string passed to getElementById() error exists only in Firefox, other browsers are less "explicit" and return null or HTML element (I'm not saying, maybe there might be a similar browser to Firefox).

An attempt to solve the problem

If jQuery knows that the query is an object, it may not have to interpret it:

$(document.getElementById("checkParcelamento"));
    
20.10.2016 / 12:45
0

The error is being generated in some Firefox extension, not in your code.

PS: I also use the Gerencianet Checkout API and your code is correct (payment with card).

You are free to use both id (#) and class (.) in the jQuery selector, it works the same way, remembering that for ID you can have as many selectors but only one element with that ID on the page, you can have as many selectors and elements as you want, it is more advantageous to use a class because you can have more than one event trigger on the same page without any problems.

    
08.03.2017 / 15:05
0

in fact the problem is probably out of the code presented as previously reported in this post , lack of attribute in label

When missing id in label

<label for="">Stuff:</label>

corrected

<label for="someID">Stuff:</label>
    
01.12.2018 / 15:00