Hi I am quite new to web developing and I am starting to struggling with this code. I am basically trying to enter a name along with a mark and store this in a javascript cookie. From this I want to create the mean and graph for up to 100 results.
This is the code:
<html>
<head>
<title>Class Marks Calculator</title>
<link rel="stylesheet" type="text/css" href="site.css" />
<script type="text/javascript">
var num = 0;
function createcookie()
{
if(num<100)
{
num = num + 1;
var name = escape(document.marks.name.value)+";";
var mark = escape(document.marks.mark.value)+";";
document.cookie[0]= "name = "+name+ " mark = "+mark;
}
else
{
alert("Max marks exceeded");
}
}
function readCookie(name)
{
var nameEQ = name +"=";
var ca = document.cookie.split(';');
//for(var i=0;i<ca.length;i++)
//{
var i = 0;
var c = ca[i];
while(c.charAt(0)==' ')
document.write("value is "+ c.substring(nameEQ.length, c.length));
//}
return null;
}
function eraseCookie()
{
createCookie(name,"",-1);
}
</script>
</head>
<body>
<center>
<div id="container">
<div id="logo">
<p align="left">
<img src="logo.jpg" width="400" height="90" alt="logo" />
</p>
</div>
<center>
<div id="linksContainer">
<a href="page1.htm">Graphs and Charts</a> | <a href="page2.htm">Statistics</a> | <a href="page3.htm">Previous Calculations</a>
</div>
</center>
<div id="textContainer">
<h1><p align="left">Home Page</p></h1>
<br />
<p>Please enter the name of student and the mark they achieved:</p>
<form name="marks">
<table>
<tr><td>Student Name:</td><td><input type="text" name="name" size="20" /></td></tr>
<tr><td>Student Mark:</td><td><input type="text" name="mark" size="20" /></td></tr>
<tr><td><input type="button" value="Create Cookie" onclick="createcookie()" /></td></tr>
<tr><td><input type="button" value="Get Cookie" onclick="readCookie('bob')" /></td></tr>
</table>
</form>
<br />
</div>
</div>
</center>
</body>
</html>
I have been working on this for hours and do not understand where I am going wrong.
Thanks in advance