Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

121
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!