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

245
Views
Check if a variable is greater than or equal to a number and less than or equal to a number jquery

I am trying to write code that will take a number from an HTML input field.

  • if the number is greater than or equal to 10000 then set a new variable to 10000

  • if it is less than or equal to set the new variable to the same value as the other variable.

var sc = $('#Single-num1').val(); // Water Amount input
console.log(sc);

This is the first variable (sc).

This is what I am trying to get working and the logic makes sense but it won't give me data.

if (sc >= 10000) {
  var ssa = 10000;
}
else {
  var ssa = sc;
}
<div class="singlewateramountdiv">
  <label for="Single-Water-Amount">How Much Water Was Used?</label>
  <input type="text" id="Single-num1" name="Single-num1"/>
</div>
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Convert the string to a number and do a simple check

var sc = Number($('#Single-num1').val());

var ssa = sc;
if (sc > 10000) ssa = 10000;

with a ternary

var sc = Number($('#Single-num1').val());

var ssa = (sc > 10000) ? 10000 : sc;

with Math.min

var sc = Number($('#Single-num1').val());
var ssa = Math.min(sc, 10000);
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!