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

69
Views
localStorage.removeItem does not remove the Date from input field

I have this code for saving Date in local storage, but my localStorage.removeItem is not working.
Can you tell me what I am doing wrong?

let today = new Date().toISOString().slice(0, 10)
document.getElementById("datata").value = getSavedValue("datata");
document.getElementById("exdated").value = getSavedValue("exdated");

function saveValue(e) {
  var id = e.id;
  var val = e.value;
  localStorage.setItem(id, val);
}

function getSavedValue(v) {
  if (!localStorage.getItem(v)) {
    return today;
  }
  return localStorage.getItem(v);
  localStorage.removeItem(v);
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You need to remove before the return statement.

let today = new Date().toISOString().slice(0, 10)
document.getElementById("datata").value = getSavedValue("datata"); 
document.getElementById("exdated").value = getSavedValue("exdated"); 
function saveValue(e){
   var id = e.id;  
   var val = e.value; 
   localStorage.setItem(id, val); 
}
   
function getSavedValue  (v){
   if (!localStorage.getItem(v)) {
    return today;
   }

   var item = localStorage.getItem(v);
   localStorage.removeItem(v); 
   return item;   
}
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!