[CODE]<html>
<head>
</head>
<body>
<script>
function WriteCookie()
{
if( document.myform.customer.value == “” )
{
alert (“Enter some value!”);
return;
}
cookievalue= escape(document.myform.customer.value) + “;”;
document.cookie=”name=” + cookievalue;
document.write (“Setting Cookies : ” + “name=” + cookievalue );
}
function ReadCookie()
{
var allcookies = document.cookie;
document.write (“All Cookies : ” + allcookies );
// 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 (cookievalue);
}
}
</script>
<form name=”myform” action=””>
Enter name: <input type=”text” name=”customer”/>
<input type=”button” value=”Set Cookie” onclick=”WriteCookie();”/>
</form>
<form name=”back” action=””>
<p> click the following button and see the result:</p>
<input type=”button” value=”Get Cookie” onclick=”ReadCookie()”/>
</form>
</body>
</html>
I was reading [url]http://www.tutorialspoint.com/javascript/javascript_tutorial.pdf
Its about cookies data writing/reading.
I tried to combine 2 codes from examples.
The problem is:
If I write something in empty field and click [ENTER], then
click on ‘get cookie’ button… I see no cookies, while according idea I should.
Maybe I understood something wrong or skipped?