Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

187
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda