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

107
Visualizações
Function returing null

I'm trying to get the value from an number input type but when i try to show the value it returns a null (ps: sorry I'm still a highschool student) HTML:

  <label for="nummatch"><h2>Number of Match/es:</h2></label>
        <input type="number" onkeyup="stop(this)" id="nummatch" name="number of matches" value="1" min="1" max="5">
        <br>
        <a  href="../html/Game Page.html#vsComputer"><button onclick="number()"><h1>VS Computer</h1></button></a>

JavaScript

   function number(){
       var times = document.getElementById("nummatch").value;
       return timesNum;
    }
       var time = number();
       console.log(time)

the console.log returns a error "Uncaught TypeError: Cannot read properties of null (reading 'value')"

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

As I can see, you're returning a different variable name inside the 'number' function.

Here is a correct JavaScript code with full HTML Code:

Finally, I hope that's clear and helpful, Thanks!.

<label for="nummatch"><h2>Number of Match/es:</h2></label>
<input type="number" onkeyup="stop(this)" id="nummatch" name="number of matches" value="1" min="1" max="5">
<br>
<a href="../html/Game Page.html#vsComputer"><button onclick="number()"><h1>VS Computer</h1></button></a>


<script>
    function number() {
        var times = document.getElementById("nummatch").value;
        return times;
    }
    var time = number();
    console.log(time)
</script>

about 4 years ago · Juan Pablo Isaza Relatório

0

Something is missing. You add a onkeyup event which calls the function stop(). I add this function to your code and it works well.

function stop() {
  var time = number();
  console.log(time)
}

function number(){
  var times = document.getElementById("nummatch").value;
  return times;
}
  <label for="nummatch"><h2>Number of Match/es:</h2></label>
  <input type="number" onkeyup="stop(this)" id="nummatch" name="number of matches" value="1" min="1" max="5">
  <br>
  <a  href="../html/Game Page.html#vsComputer"><button onclick="number()"><h1>VS 

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