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

384
Vistas
Why is jQuery .val() returning nothing?

I am trying to get the value of an input. Here is what my form looks like:

enter image description here

This is the HTML for it:

<label for="userName"></label>
<input type="text" class="form-input plain-text" id="userName" placeholder="Username">

Here is the jQuery to get its value and log it:

$("#loginSubmit").click(function() {
    var userName = $("#userName").val();
    console.log(userName);
});

But when I type in some text and hit the login button that has the id #userName, the console returns this:

enter image description here

Why does this not output dwedwed in the console?

Thanks


Solution found in comments

Debugging: I found I have more than one input with the same ID

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Immediate reasons I can see are:

  • you are attaching an event before the DOM is even loaded or before the element is available in the DOM (if you're loading JS in the head instead of bottom of body for example)
  • multiple element's with the same ID
  • you have a stopPropagation on button elements (or this particular identifier) which is blocking the callback

Other than the above, it's hard to determine what is going on without more code/information.

If its a matter of when you are attaching the listener, try adding $(document).ready() around your event listener.

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