Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

249
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda