abdelelbouhy Posted September 4, 2010 Share Posted September 4, 2010 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 More sharing options...
jeffman Posted September 4, 2010 Share Posted September 4, 2010 Try";expires=" + date; Link to comment Share on other sites More sharing options...
abdelelbouhy Posted September 4, 2010 Author Share Posted September 4, 2010 Try";expires=" + date;thank you very much as i always say you are the best in this forum Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.