Jump to content

cookie help


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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Create New...