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

123
Visualizações
Javascript: disable element on countdown to date

I have a button which I disable depending on whether an datetime has passed, however, this will only work on page load, how can I set a countdown timer so that my button is disabled when the countdown to the nominationCloseDateTime is reached even if the page is already loaded.

<ctx><vars><nominationCloseDateTime>2022-05-10 04:56:00.000Z</nominationCloseDateTime></vars></ctx>

var nominationCloseDateTime = document.controller.getValue('/ctx/vars/nominationCloseDateTime');

if (nominationCloseDateTime < $.now()) {
    $('input#nominate').prop('disabled', true);
}

I've calculated the countdown to date in seconds, now whats next?

 var nominationCloseDateTimeCountDownSecs = ((new Date(document.controller.getValue('/ctx/vars/nominationCloseDateTime')).getTime()) - new Date().getTime()) / 1000;

Is the following correct?

setTimeout(() => {
  $('input#nominate').prop('disabled', true);
}, nominationCloseDateTimeCountDownSecs)
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You want to use a setTimeout() function.

For example,

//calculate, in seconds, how much time you want the button to stay enabled.
const calculatedTimeUntilCloseDateTime;

setTimeout(() => {
  functionToDisableYourButton();
}, calculatedTimeUntilCloseDateTime)

It will work like below:

setTimeout(() => {
  console.log("Delayed for 1 second.");
}, 1000)

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