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

68
Visualizações
jQuery event not attaching to the input field

I have a field called as cellphoneDetails, I am trying to attach an invalid event to it, but it is not attaching the event to it

$(document).ready(function(e) {
  var x = document.getElementById("contactEditForm");

  if (x.addEventListener) {
    var error = 0;
    alert('bingo');
    x.addEventListener("submit", function(e) {
        alert('test test');
        $("##CellphoneDetails").on("invalid", function() {
          alert($(this).val());
          error = 1;
          if ($(this).val() != '') {
            $(this).focus();
            $("##cellValidDetails").css('display', 'block');
          }
        });
      }
    }
  });

the HTML has the pattern added to it which validates if the value is entered, it should be a valid cellphone number else if its empty, do not validate it and move ahead

but due to some issue, the event is not attaching to the submit call and making a mess

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

First thing I noticed is that it should be $("#CellphoneDetails"), not $("##CellphoneDetails"), and $("#cellValidDetails") instead of $("##cellValidDetails").

To target and ID, you only need one #.

Also, I believe (x.addEventListener) will always be undefined.

You have a mix of JS and jQuery, I'd suggest just using one or the other primarily.

about 4 years ago · Juan Pablo Isaza Relatório
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