<jojowebdev@gmail.comwrote in message
news:1152890745.235911.73520@i42g2000cwa.googlegro ups.com...
Quote:
Do javascript cookies REALLY have to be this hard?
Well... yes and no.
"Yes" because all that code you showed is needed: cookies in Javascript can
be very completed (especially to people new to JavaScript) since the
language doesn't abstract their handling. You're left do all the string
parsing, date manipulation and so forth.
"No" because it's actually pretty simple to abstract things for yourself.
Try this:
http://www.depressedpress.com/Conten...kies/Index.cfm
This script will create a cookie managment object which will abstract cookie
handling into method calls to the objects. No global functions are created,
only the single object: "DP_Cookies" (which, itself, does of course have
functions... but you don't need to worry about them as they are encapsulated
into the object).
To set your cookie (after importing this script) you would do:
DP_Cookie.set("whatField", "nbcarrier1");
That would create a session cookie - it will be destroyed when the browser
session ends. To create a cookie that lasts one day you could add:
DP_Cookie.set("whatField", "nbcarrier1", 1);
To change that so the cookie lasts 30 minutes you can do this:
DP_Cookie.set("whatField", "nbcarrier1", 30, "minutes");
To later get the value of the cookie you can do:
var MyCookieValue = DP_Cookies.get("whatField");
To later erase (delete) the cookie do:
DP_Cookies.erase("whatField");
The object also provides methods to easily get all cookies (as a JavaScript
Object) and erase all cookies.
There's full documentation at the link I provided and the object is open
source (under the very liberal BSD license) and free.
I hope it helps,
Jim Davis