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

121
Vistas
input value on keyup (codepen)

I have an issue on this codepen https://codepen.io/Kimple/pen/MWEBGZy?editors=0011

In the function titleCheck(), I want to get the value of <input type="text" id="title" placeholder="title"> But I always get an empty value, and I don't know why.

I tried the same code on JSFIDDLE and had the same issue.

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

0

You saved the value into the variable when initialized, therefore when the input is empty. The value does not update itself automatically. You need to ask for it with every key press. This way it should log the correct value:

 function titleCheck() {
        title.addEventListener('keyup', (event) => {
            console.log(title.value) // ask for the value every time to see it updating
            titleValue = title.value
            if (titleValue != '') {
                checkBox.checked = true;
                checkboxCheck();
            } else {
                checkBox.checked = false;
                checkboxCheck();
            }
        })
    }
    titleCheck()

Also next time try using snippets in your answer instead of link to codepen or other external editor.

about 4 years ago · Juan Pablo Isaza Denunciar

0

You have to reassign titleValue, because you set it to empty on beginning and don't change it afterwards

   function titleCheck() {
        title.addEventListener('keyup', (event) => {
            titleValue = document.getElementById("title").value
            console.log(titleValue)
            if (titleValue != '') {
                checkBox.checked = true;
                checkboxCheck();
            } else {
                checkBox.checked = false;
                checkboxCheck();
            }
        })
    }
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