Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

105
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!