Click to See Complete Forum and Search --> : cookie code problems


domuk
11-11-2003, 10:39 AM
Hi all,

I am having problems getting the following script to work. I think the problems is in the way that i am passing the variable v1 to the

line:

SetCookie (v1.name, v1.value, expdate);

by:

var v1 = eval(document.form1.v1.value)


Also could someone please point me in the direction of a document that explains how cookies work (line by line??)

your help would be very much appreciated

Thanks in advance...


Dom

_______________________________________________________



<html>
<head>
<title>make</title>
<script language="JavaScript">

function SetCookie (name, value)

{
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2) ? argv[2] : null;
var path = (argc > 3) ? argv[3] : null;
var domain = (argc > 4) ? argv[4] : null;
var secure = (argc > 5) ? argv[5] : false;
document.cookie = name + "=" + escape (value) +
((expires == null) ? "" : ("; expires="+
expires.toGMTString())) +
((path == null) ? "" : ("; path=" + path)) +
((domain == null) ? "" : ("; domain=" + domain)) +
((secure == true) ? "; secure" : "");
}


function save_all()

{
save_v1()
}


function save_v1()

{
var v1 = eval(document.form1.v1.value) //i think this is wrong
var expdate = new Date ();
expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000 * 31));
SetCookie (v1.name, v1.value, expdate); // ??????? this line
}

</script>

</head>



<form name="form1">
<b>v1</b>
<input type=text size=30 name="v1">
<p>
<b>v2</b>
<input type=text size=30 name="v2">
<p>
<b>vt</b>
<input type=text size=30 name="vt">
<p>
<input type="button" name="Button" value="save" onClick="save_all()">
</form>

</body>
</html>