Click to See Complete Forum and Search --> : document.cookie


Tricky123
12-03-2002, 06:02 AM
Hi there!

I have used to following script to write a cookie that contains data from form input:
function writeCookie()
{
var cookieName = "MyCookie"
var name = document.form1.firstname.value;
var lastname = document.form1.lastname.value;
var flower = document.form1.flower.value;

var nextYear = new Date();
nextYear.setFullYear(nextYear.getFullYear() + 1);


var cookie = "MyCookie=" + cookieName + "; version=" + document.lastModified + "; expires=" + nextYear.toGMTString() + "; secure ;" + " |" + name + "|" + lastname + "|" + flower + "|" ;


document.cookie = escape(cookie);
}

And to some extent this works in that it is possible to unescape(cookie) and read the data back. However, the cookie does last beyond the session despite the expires date being set.

can any one tell me why and show me how to correct the problem?

TIA

Tricky

Tricky123
12-03-2002, 09:13 AM
Dave,
Thanks!

sorry this is so long!!

That code works but doesn't match my needs. This then escapes all the data but to a non text file which is what I think I need as I am going to encode my HTML input variables as XML then send this to a cookie text file for storage then retrieve this at a later date so that it can be read by a VB program and e-mailed. You might be wondering why I don't just e-mail the data straight away? Well this is because my program is not attached to a server.

I guess what I need is to add data to a cookie for storage as a txt file.

I had planned on getting writing a Javascript function that could write data to a text file but it would appear that for security reasons this is not possible!

your views would be greatly appreciated!!



Tricky