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

115
Views
Cookie not Saving

Guys I am trying to catch something form the screen (email) when the form is opened & then save it in the cookie so I can use it for after the form is closed & show it somewhere else! I wrote this code. I hope its clean enough to be understood! Everything is working except that it is not saving in the cookie 🍪 here is the code:

//singelton works always
let start = isFormOppened();

while (start) {
  if (isFormOppened && doesEmailInputExist && getBtn) {
    console.log('code works');
    getBtn().addEventListener('click', (e) => {
      setCookie('email', getEmailValue(), 1);
      console.log('cookie saved successfully');
      start = false;
    });
  }
}

function isFormOppened() {
  if (!document.querySelector('.cb-hp__wrapper')) {
    return false;
  }
  return true;
}

function doesEmailInputExist() {
  if (!document.querySelector('#email', '.cb-text__control')) {
    return false;
  }
  return true;
}

function getBtn() {
  if (document.querySelector('button', '.cb-button')) {
    return document.querySelector('button', '.cb-button');
  }
}

function getEmailValue() {
  if (!document.querySelector('#email', '.cb-text__control')) {
    return -1;
  }
  return document.querySelector('#email', '.cb-text__control').value;
}

function setCookie(name, value, days) {
  var expires = '';
  if (days) {
    var date = new Date();
    date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
    expires = '; expires=' + date.toUTCString();
  }
  document.cookie = name + '=' + (value || '') + expires + '; path=/';
}

function getCookie(name) {
  var nameEQ = name + '=';
  var ca = document.cookie.split(';');
  for (var i = 0; i < ca.length; i++) {
    var c = ca[i];
    while (c.charAt(0) == ' ') c = c.substring(1, c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
  }
  return null;
}

function eraseCookie(name) {
  document.cookie =
    name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}
about 4 years ago · Santiago Gelvez
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!