Jump to content

cookie help


abdelelbouhy

Recommended Posts

hello guys i'm trying to set cookie for the user name then read it and insert it to the form control it works fine when i reload the page but when i close the browser and reopen doesn't read it so i put the expires 2020 but still not working please check this script and help mevar userName ;var password ;function setCookie(){ var date = new Date('june 10, 2020'); date = date.toGMTString(); userName = document.getElementById('name').value; password = document.getElementById('pass').value; theCookie = "userName=" + userName; document.cookie = theCookie; theCookie += ";expires" + date; document.cookie = theCookie;}function readCookie(){ var cookies = document.cookie.split(';'); for(i=0; i < cookies.length ; i++){ var subcookie = cookies.split('='); var cookiename = subcookie[0]; var cookievalue = subcookie[1]; if(cookiename == "userName") { document.getElementById('name').value = cookievalue; } } }window.onload = function(){ readCookie(); document.getElementById('submit').onclick = setCookie;}

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...