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

118
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 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