I am not a programmer. I am trying to use a cookie script that remembers the last drop down menu selection.
I found a script that works but it does only a session cookie. How do I add an expiration date to the cookie in this script?
<head>
<script>
function SETcookie() {
document.cookie = "Selected=" + document.getElementById('myList').selectedIndex;
}
function GETcookie() {
if (document.cookie) {
eval(document.cookie);
document.getElementById('myList').selectedIndex = Selected;
}
}
</script>
</head>
<body onLoad="GETcookie()">
<select id="myList" onChange="SETcookie()">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
</select>
</body>
COOKIES, COMMERCIALLY PACKAGED - UNOPENEDProperly stored, a package of unopened cookies will generally stay at best quality for about 6 to 9 months.
Cookies, Crackers and Chips When cookies or chips get old, the stale taste is quite obvious. But as long as it doesn't smell funky (the oils in the cookie may go bad over a long period of time) and it doesn't crumble apart in your hand, then it's okay to eat.
Cookies typically expire somewhere between 30 and 90 days. Though, some companies do implement shorter cookie expiration dates. It's also important to note that cookies can be deleted manually by the user or through third-party security programs. The cookie expiration time is very important.
What is the timeout of Cookie? The default time for a Cookie to expire is 30 minutes. The default Expires value for a cookie is not a static time, but it creates a Session cookie. This will stay active until the user closes their browser/clears their cookies.
Try this:
function setCookie(c_name,c_value,exdays) {
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
document.cookie=encodeURIComponent(c_name)
+ "=" + encodeURIComponent(c_value)
+ (!exdays ? "" : "; expires="+exdate.toUTCString());
;
}
c_name
is the name of the cookie
c_value
is the cookie value
exdays
is the number of days you want the cookie to expire after
Source: http://www.w3schools.com/js/js_cookies.asp
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With