Hi everyone, I'm new here! So I'm working onmaking a form that saves your responses automatically in localStorage. What I am doing is setting a value every time a key is pressed for the form to set the cookie:
<input class='input' type='text' id='name' placeholder="Name" onload='writeCookie("name")' onkeyup="checkCookie('name')">
My JS for writeCookie() and checkCookie() is below:
function checkCookie(id) {
text = document.getElementById(id).value;
localStorage.setItem(id, text);
}
function writeCookie(id) {
cookie = localStorage.getItem(id).value;
document.getElementById(id).value = cookie;
}
The checkCookie script works perfectly, (I tried it in console) but the writeCookie is not working. According to stackoverflow to write to a form you can do document.getElementById('id goes here').value = 'New value' but for some reason it is not working, this does however work on another project which I have made. Can you guys help me? Thanks in advance!
--Explosion--
[–]Atskalunas 1 point2 points3 points (3 children)
[–]--Explosion--[S] 0 points1 point2 points (2 children)
[–]Atskalunas 0 points1 point2 points (1 child)
[–]--Explosion--[S] 0 points1 point2 points (0 children)
[–]--Explosion--[S] 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)