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

169
Views
How to take an HTML integer input and work with it in JavaScript

I have been trying to make a calculator website as practice to learn HTML, CSS and JS. However, I need help with fetching an integer value from HTML and working with it in javascript. here is my code

HTML:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="3D.css">
    <title>3D Shapes Calculator</title>
</head>
<body>
<div class="spearesSection">
        <div class="spearesSectionHeading" id="sectionSpearesHeading">
            <p class="spearesSectionText">Calculate the Volume of a Speare!</p>
        </div>
        <div class="workAreaSpeares">
            <img class="spearesPicture" src="../Images/Speare.jpg" alt="Error, Page cannot be loaded">
            <p class="textSpearesRadius">Radius:</p>
            <input type="number" class="inputRadiusSpeare" id="radiusInput">
            
            <button class="buttonExecuteSpeares" id="buttonExecuteSpeares" onclick="spearesSolve()">Solve!</button>
            <p class="answerSpeare"> Answer =</p>
            <div class="outputAreaSpeare"></div>
            <p class=answerSpearePi>In Terms of Pi =</p>
            <div class="outputAreaSpearePi"><p class="piSpeare">π</p></div>
        </div>
    </div>
</body>
<script src="3D.js"></script>
</html>

JS:

let radiusInput = document.getElementById("radiusInput").Value;
let radiusOutput;

function spearesSolve() {
    radiusOutput = (radiusInput ** 3) * 3.14159265359 * (4/3);
   console.log(radiusOutput)
}

PS: I didn't include my to keep it neat

about 4 years ago · Santiago Gelvez
1 answers
Answer question

0

You need to get the input value in the click handler, also value should be lowercase.

let radiusInput = document.getElementById("radiusInput");
let radiusOutput;

function spearesSolve() {
    radiusOutput = (radiusInput.value ** 3) * 3.14159265359 * (4/3);
   console.log(radiusOutput)
}
about 4 years ago · Santiago Gelvez 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!