Hello. I create cookies, but for some reason the value of the input is not written to the value of the cookie. What did I do wrong?
<form> <input type="text" id="first" placeholder="Введите имя"> <input type="button" id="done" value="Готово!"> </form> <script> var init = function() { var expDate = new Date(); expDate.setMonth(expDate.getMonth() +1); var cookieVal = document.getElementById("first").value; document.cookie = "first" + "=" + cookieVal + ";path=/;expires=" + expDate.toGMTString(); var valArray = document.cookie.split(";"); return valArray[1]; } document.getElementById("done").onclick = init; document.getElementById("first").value = init(); </script>