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

170
Visualizações
uncaught TypeError cannot read properties of undefined

I'm trying to console.log the value submitted by a form but getting "uncaught TypeError cannot read properties of undefined" Error. I'm not sure why.

HTML

<form action="" id="p2Input">
    <input type="text" name="" id="guess" placeholder="Guess a letter">
    <input type="submit" value="Guess">
                     
</form>

JavaScript

function processGuess(event){
    event.preventDefault(); //this is where the error shows
    let guess = document.getElementById("guess").addEventListener("Submit",null);
    console.log(guess);
}
about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

You should call processGuess when form has submitted, you can do it, by defining onsubmit on your form, like this:

function processGuess(event){
    event.preventDefault(); 
    let guess = document.getElementById("guess").value;
    console.log(guess);
}
<form action="" id="p2Input" onsubmit="processGuess(event)">
  <input type="text" name="" id="guess" placeholder="Guess a letter">
  <input type="submit" value="Guess">
</form>

about 4 years ago · Santiago Gelvez 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