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

213
Vistas
Why is the value of my password field always an empty string?

I've been working on my javascript skills lately and the password validation has given me a lot of trouble. The last thing that is stopping me is that the password field always has a value of an empty string for some reason.

It always logs out an empty string, no matter what i put in the input field. I've tried a different browser but that did not have an effect.

<input type="password" id="password">
<button type="submit" onclick="submitIt()">
Submit
</button>

js

const passWord = document.getElementById('password').value

function submitIt() {
console.log(passWord)
}

Here is the jsfiddle: https://jsfiddle.net/k4owfLzn/3/

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

0

Your value is always empty because the value of passWord is set on the loading of page. It is not updated after a user types in a value.

If you modify the code so it is like this you should get the value.

function submitIt() {
  const passWord = document.getElementById('password').value;

  console.log('passWord: ', passWord)
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

const passWord

was declared outside the function. I am sure that if you insert it inside the function, you will have the result you were looking for. :)

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