I am getting a url parameter (referrer) and then setting it as a cookie – this works great.
*I then want to retrieve the cookie value into a variable and then set the cookie value into the innterHTML and value of an input box. – this code (the retrieveReferrer function seems to do nothing). *
Where am I going wrong? and is their a tinder, simpler way to achieve all of this?
const queryString = window.location.search;
if(queryString.length > 0) {
const urlParams = new URLSearchParams(queryString);
const referrerID = urlParams.get('referrer');
setCookie('referrerID', referrerID, 1);
}
// Set a Cookie
function setCookie(cName, cValue, expDays) {
let date = new Date();
date.setTime(date.getTime() + (expDays * 24 * 60 * 60 * 1000));
const expires = "expires=" + date.toUTCString();
document.cookie = cName + "=" + cValue + "; " + expires + "; path=/";
}
function retrieveReferrer() {
var StoredReferrer = getCookie("referrerID");
console.log(StoredReferrer)
var divElem = document.querySelector(".booking-referrer .el-input__inner").innerHTML = StoredReferrer;
var divElem2 = document.querySelector(".booking-referrer .el-input__inner").value = StoredReferrer;
}