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

199
Visualizações
How to check if time passed (timer)

I have code:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Get the Value of Text Input Field in JavaScript</title>
</head>
<body>
    <input type="number" placeholder="Type something..." id="myInput">
    <button type="button" onclick="getInputValue();">Get Value</button>
    
    <script>
        function getInputValue(){
            // Selecting the input element and get its value 
           // var inputVal = document.getElementById("myInput").value;
          var d = new Date();
          var n = d.getTime();
          var number = (document.getElementById("myInput").value);
          number=parseInt(number);
          var inputVal= number+n;
            
            alert(inputVal);
        }
       
        
        
    </script>
</body>
</html>

In the code I'm checking current time in milliseconds and in the form I write time in ms and sum current time with time in form and for example I want to add to current time 6000 ms and before this 6000 ms pass I want to pass for example to website information "ON" and after that "OFF". Should i use here loop to check if this time passed or I can do it other way ?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

using requestAnimationFrame API to make a recursion

codepen demo timer

about 4 years ago · Juan Pablo Isaza Relatório

0

Let me know if something is not clear (I just really do not know what might be complicated here)

Except for +val, this is instead of parseInt(val)

Except2 for | 0, this is instead of toFixed()

$('#info').hide();
const getInputValue = ()=>{
    const val = $('#myInput').val();
    $('#info').fadeIn();
    console.log(`info here for ~${(+val / 1000) | 0} sec`);
    setTimeout(()=>{
        $('#info').fadeOut();
    }, +val);
};
*{padding:10px}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>

<input type="number" value="2000" placeholder="Type something..." id="myInput" />
<button type="button" onclick="getInputValue();">Show Info</button>
<div id="info">Website information "ON"</div>

JQuery is not needed here

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