i've got a program that gets input from a user, and then stores it in a cookie. That bit is fine, what is a problem is that its just overwriting the data each time a new entry is made, i believed this to be something do do with it not being numbered entry's, so i added a number into the entry, but for some reason it wont add 1 to the number variable each time the function is called
Can anybody see why?
<html>
<head>
<title>Grader 101</title>
<link href="styles.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
body,td,th {
font-family: Calibri, Tahoma, Arial Narrow;
font-size: 12pt;
}
-->
</style>
<script type="text/javascript">
var num = 0;
function WriteCookie()
{
var allowed=/^[a-zA-Z]+$/;
if(document.gradeAdd.studentName.value.match(allowed))
{
num = num+1;
student=escape(document.gradeAdd.studentName.value)+";";
score=escape(document.gradeAdd.studentGrade.value)+";";
document.cookie="Student" + num + "=" + student;
document.cookie="Score" + num + "=" + score;
}
else
{
alert("Enter a valid name");
return;
}
}
function ReadCookie()
{
var allcookies = document.cookie;
alert("All Cookies : " + allcookies );
cookiearray = allcookies.split(';');
for(var i=0; i<cookiearray.length; i++)
{
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
}
}
</script>
</head>
<body class="oneColFixCtrHdr">
<div id="container">
<div id="header">
<h1>Grader 101 </h1>
</div>
<div id="mainContent">
<form name="gradeAdd" method="post" action="">
<p>Please enter the student name and the number of marks achieved</p>
<table width="1211" border="0">
<tr>
<td width="113">Student Name:</td>
<td width="120"><input type="text" name="studentName" size="20"></td>
<td width="15"> </td>
<td width="124">Student Grade:</td>
<td width="120"><input type="text" name="studentGrade" size="20"></td>
<td width="86"><label>
<input type="submit" name="addItem" id="button" value="Add Details" onClick="WriteCookie()">
</label></td>
<td width="105"><label>
<input type="submit" name="clearRecords" id="button2" value="Clear Records">
</label></td>
<td width="494">
You have approximately records
</td>
</tr>
</table>
</form>
<hr>
<p>Below are your options to: View the Marks, Show the Mean, Show the Standard Deviation, Show a Graph</p>
<table width="550" border="0">
<tr>
<td><input type="button" name="showMarks" value="Show the Marks" onClick="ReadCookie()"></td>
<td></td>
<td><input type="button" name="showMean" value="Show the Mean"></td>
<td> </td>
<td><input type="button" name="showStdDev" value="Show the Standard Deviation"></td>
<td> </td>
<td><input type="button" name="showGraph" value="Show a Graph"></td>
</tr>
</table>
<hr>
<p> </p>
</div>
</div>
</body>
</html>