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

165
Views
disable button while retrieving data from local storage and updating the date input

I am trying to implement a function that checks if the date and time I choose have already been chosen before, if so, it gives an error, if not it lets me carry on with adding the ticket. The current function does save options to local storage, however it looks like it doesn't retrieve them for me and allows me to choose the same date twice.

var count = 0;
function store() {

  let clickCounter = localStorage.getItem("clickCount");
  if (!clickCounter) {
    localStorage.setItem("clickCount", 0);
    clickCounter = "0";
  }
  clickCounter = parseInt(clickCounter);
  document.getElementById('inc').value = ++count;
  if (clickCounter == 100) {
    console.log("Limit reached");
    return;
  } else {
    localStorage.setItem("clickCount", clickCounter + 1);
  }
  console.log("Saving");
  var e = document.getElementById("time");
  var time = e.options[e.selectedIndex].text;
  var date = document.querySelector("input").value;

  localStorage.setItem(JSON.stringify(time), date);

  console.log(localStorage);
  if (!localStorage.getItem("history")) {
    localStorage.setItem("history", "[]");
  }
  const history = JSON.parse(localStorage.getItem("history"));
  history.push({ [JSON.stringify(time)]: date });
  localStorage.setItem("history", JSON.stringify(history));
  console.log(localStorage.getItem("history"));

}

function myDate(date) {

  var today = new Date();
  var newDate = new Date(date);
  var nextWeek = new Date();
  var pastWeek = new Date();
  nextWeek.setDate(nextWeek.getDate() + 7);
  pastWeek.setDate(pastWeek.getDate() - 7);
  const dateInput = document.getElementById('date');

  if (newDate < pastWeek || newDate > nextWeek) {
    document.getElementById("time").disabled = true;
    console.log("error")

    return;
  } else {
    document.getElementById("time").disabled = false;
  }
}
about 4 years ago · Juan Pablo Isaza
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!