Guest_imported
New member
- Jan 1, 1970
- 0
I’m trying to get some cookies set up on my but, like so many others; I haven’t a clue what I’m doing! I’ve tried to edit a script I found down the back of my sofa (it’s always the first place I look), but with no luck.
The fields I’d like the cookie to remember are: name, email, url, url_title
I keep getting this error: Error: 'email' is underfined
I've put the script just after this:
<form method=POST name="MyForm" action="
You can view the board here (This test board's not working yet, but I'm just working on the cookies at the moment).
Does anybody know what I'm doing wrong?
The fields I’d like the cookie to remember are: name, email, url, url_title
I keep getting this error: Error: 'email' is underfined
I've put the script just after this:
<form method=POST name="MyForm" action="
You can view the board here (This test board's not working yet, but I'm just working on the cookies at the moment).
Does anybody know what I'm doing wrong?
Code:
<SCRIPT LANGUAGE = "JavaScript">
<!--
// Use this function to retrieve a cookie.
function getCookie(name){
var cname = name + "=";
var dc = document.cookie;
if (dc.length > 0) {
begin = dc.indexOf(cname);
if (begin != -1) {
begin += cname.length;
end = dc.indexOf(";", begin);
if (end == -1) end = dc.length;
return unescape(dc.substring(begin, end));
}
}
return null;
}
// Use this function to save a cookie.
function setCookie(name, value, expires) {
document.cookie = name + "=" + escape(value) + "; path=/" +
((expires == null) ? "" : "; expires=" + expires.toGMTString());
}
// Use this function to delete a cookie.
function delCookie(name) {
document.cookie = name + "=; expires=Thu, 01-Jan-70 00:00:01 GMT" + "; path=/";
}
var exp = new Date(); // make new date object
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31)); // set it 31 days ahead
with (document.MyForm) {
setCookie("name", name.value, exp);
setCookie("email", email.value, exp);
setCookie("url", url.value, exp);
setCookie("url_title", url_title.value, exp); // save the cookie
}
document.write(getCookie("name") + "<br>" +
getCookie("email") + "<br>" +
getCookie("url") + "<br>" +
getCookie("url_title")); // retrieve and display cookie on page
delCookie("name");
delCookie("email");
delCookie("url");
delCookie("url_title"); // delete cookie
//-->
</SCRIPT>