Is it possible to name a cookie in javascript?
i've got a web program that will display
"name:undefined Name:Jack Grade:32"
whenever i display the contents of a cookie i create. i'm assuming th first bit is the cookie name itself and then the other two bits are the contents?
also, when i try to add a new bit to the cookie it just overwrites it, is their a way i can add it to the end of this one. so it displays
name:undefined Name:Jack Grade:32
name:undefined Name:Billy Grade:72
???
here is the code i have
<script type="text/javascript">
function WriteCookie()
{
var allowed=/^[a-zA-Z]+$/;
if(document.gradeAdd.studentName.value.match(allowed))
{
cookievalue=escape(document.gradeAdd.studentName.value)+";";
cookievalue2=escape(document.gradeAdd.studentGrade.value)+";";
document.cookie="Name = " + cookievalue;
document.cookie="Grade = " + cookievalue2;
alert(document.cookie);
}
else
{
alert("Enter a valid name");
return;
}
}
function ReadCookie()
{
var allcookies = document.cookie;
// Get all the cookies pairs in an array
cookiearray = allcookies.split(';');
// Now take key value pair out of this array
for(var i=0; i<cookiearray.length; i++)
{
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
document.write(name + ":" + value);
}
}
</script>