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

186
Vistas
Can anyone tell me why this function throws up an error when called

   <html>
    
    <script>
    
    
    function isNumber(value) {
        return typeof (value) != "boolean" && !isNaN(value) && value.length > 0;
    }
    
    function minMaxTempDecimal(value, min, max, unit) {
        console.log("D function called");
        if (value.length == 0 || value == "-") return value;
        if (!isNumber(value)) return value.substring(0, value.length - 1);
    
        value = parseFloat(value);
        if (value) < min)
            return min;
        else if (value > max)
            return max;
        return value.toFixed(1);
    
    }
    </script>
    
    <tr>
            <th>Differntial</th>
            <th><input id="differentail" type="text" name="differentail" value="1" onkeyup="this.value = minMaxTempDecimal(this.value, 0.1, 5, 0)"   /></th>
          </tr>
          
    </html>

The function does the following

  • limits the values from 0.1 to 5
  • only decimal places to one point ie step size of 0.1
  • doesn't allow characters
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Read the error. You have an extra ) in your JS code.

The following works:

   <html>
    
    <script>
    
    
    function isNumber(value) {
        return typeof (value) != "boolean" && !isNaN(value) && value.length > 0;
    }
    
    function minMaxTempDecimal(value, min, max, unit) {
        console.log("D function called");
        if (value.length == 0 || value == "-") return value;
        if (!isNumber(value)) return value.substring(0, value.length - 1);
    
        value = parseFloat(value);
        if (value < min)
            return min;
        else if (value > max)
            return max;
        return value.toFixed(1);
    
    }
    </script>
    
    <tr>
            <th>Differntial</th>
            <th><input id="differentail" type="text" name="differentail" value="1" onkeyup="this.value = minMaxTempDecimal(this.value, 0.1, 5, 0)"   /></th>
          </tr>
          
    </html>

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