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

215
Views
How can I change the display a message depending on which number the user has selected?

I want when somebody input a number lower than 4.2, my app shows message as result, but i can't make it happen.

I already tried with return.

JS code

let resultEl = document.getElementById("results")
let numberEl = document.getElementById("number__select")
let message = "mAs: 0.5 y kV: 1.0"

function calculate() {
    if (numberEl <= 4.2) {
        resultEl.textContent = message;
    } else {
        resultEl.textContent = "error"
    }
}

HTML code

<!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="styleRx.css"/>
    <script src="Rxappjs.js"></script>
    <title>HVDN Rx app</title>
</head>
<body>
    <div class="container">
        <header>
            <h1>Valoraciones de Rx</h1>
        </header>
        <div class="box">
            <form action="">
                <div class="values">
                    <label for="peso" id="peso__label">Peso</label>
                    <input class="text__input" type="number" step="0.1" id="number__select" placeholder="Peso" 
                    min="0" required>
                </div>
           
                <button id="calcular" onclick="calculate()">Calcular</button>
            </form>
            <p id="results"></p>
        </div>
        
    </div>
</body>
</html>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You have the variable numberEl set to an html element and therefor it will never be less than or equal too 4.2. Try to get the value of that element instead:

let resultEl = document.getElementById("results")
let numberEl = document.getElementById("number__select")
let message = "mAs: 0.5 y kV: 1.0"

function calculate() {
    if (numberEl.value <= 4.2) {
        resultEl.textContent = message;
    } else {
        resultEl.textContent = "error"
    }
}
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!