If you just want to get/set a cookie temporarily here's one way to do it:
function SetCookie(name, value) {
// lasts as long as the browser is open
document.cookie = name + "=" + escape(value);
}
function GetCookie(name) {
var result = null;
var theCookie = " " + document.cookie + ";";
var searchName = " " + name + "=";
var startOfCookie = theCookie.indexOf(searchName);
var endOfCookie;
if (startOfCookie != -1) {
startOfCookie += searchName.length;
endOfCookie = theCookie.indexOf(";", startOfCookie);
result = unescape(theCookie.substring(startOfCookie, endOfCookie));
}
return result;
}
> I'm new to the JavaScript world (3 days), so my question is probably very
> easy. My server doesn't support custom scripts, so all scripting has to be
> done client-side. I need to secure part of a web site with a password.
> I've got a routine that takes the contents of a password text box and
> transforms it into a number. This number is visible in VIEW---SOURCE, but
> not the actual password, so it's a little more secure. This number is then
> set as the value in a cookie. To fully simulate ASP support, any pages
> below the Log In one need to check that the cookie exists before granting
> access. I've tried everything, but nothing that gives the equivalent to
> Response.Cookies("cookiename") ="value" is readily apparant. I've tried a
> couple of functions, but with no joy.
>