We are learning client side. JavaScript applies to both server side and client side programming.  The examples given are client side.


1.                   They show that the cookie is a property of the object “document”

2.                   The cookie is dismembered with a function called split() that forms an array. The [0] element of the array is the name of the cookie and the [1] element of the array is the value.

3.                   Normally a cookie expires when the session with the browser is closed. However, in the case of cookie1.html the expire time is set to the current month plus 6. This is started in the line right after expireDate = new Date. The cookie is formed when document.cookie is loaded in function setCookie() .

4.                   The text box for entering data is creaeted at the 3rd line from the bottom. Note that when the text box is exited, i.e. onblur the function setcookie() is called.


The page cookieRead.html simply reads the cookie that was written by cookie1.html.  Note that it will read only cookies written by your access to the server with the same machine.  Cookies can only be read by the writer. Cookies on one machine are not visible to any other machine.


Note that the cookie is read by document.cookie.split(“=”)[1] which reads the cookie value, which in this case should be a name.

The function split("=") splits a string in which delimiters are = signs into an array of strings. Split() is a standard string object method that is found in Javascript and in VB.net among other places.


Let me know if you have trouble with this.


Cookies can be a lot more sophisticated. For instance, a cookie value could be used to locate information about the user that is stored in a database on the server.  Cookies are limited to 4K bytes, but a database could hold unlimited information related to the cookie.


If password validation is done with cookies, it should be simple, such as testing whether or not the pw was typed correctly into 2 different fields. Any password validation on the client side is in my opinion risky.


Try this!