Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

70
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda