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

128
Views
How do i change my start date and end date of my Calendar widget in JS?

I would like to know how do I change the start and end date of my calendar widget.

The date of the calendar should start at 1 January 2021 and I should be able to go until the Year 2030

At the moment I can go further than 2030 but I want it to stop at 2030.

    function createEventListeners() {
      var dateField = document.getElementById("tripDate");
      if (dateField.addEventListener) {
        dateField.addEventListener("click", displayCalendar, false);
      } else if (dateField.attachEvent) {
        dateField.attachEvent("onclick", displayCalendar);
      }

      var dateCells = document.getElementsByTagName("td");
      if (dateCells[0].addEventListener) {
        for (var i = 0; i < dateCells.length; i++) {
          dateCells[i].addEventListener("click", selectDate, false);
        }
      } else if (dateCells[0].attachEvent) {
        for (var i = 0; i < dateCells.length; i++) {
          dateCells[i].attachEvent("onclick", selectDate);
        }
      }

      var closeButton = document.getElementById("close");
      if (closeButton.addEventListener) {
        closeButton.addEventListener("click", hideCalendar, false);
      } else if (closeButton.attachEvent) {
        closeButton.attachEvent("onclick", hideCalendar);
      }

      var prevLink = document.getElementById("prev");
      var nextLink = document.getElementById("next");
      if (prevLink.addEventListener) {
        prevLink.addEventListener("click", prevMo, false);
        nextLink.addEventListener("click", nextMo, false);
      } else if (prevLink.attachEvent) {
        prevLink.attachEvent("onclick", prevMo);
        nextLink.attachEvent("onclick", nextMo);
      }
    }

    if (window.addEventListener) {
      window.addEventListener("load", createEventListeners, false);
    } else if (window.attachEvent) {
      window.attachEvent("onload", createEventListeners);
    }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Use the following code. Set your date first in a variable and then assign max or min date.

var today="*date*"
document.getElementById("datefield").setAttribute("max", today);
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!