Ken Ward's Java Script Tutorial ...

Cookies 3

Getting information from cookies

Enter a name in the box and then press 'Set Name'. Enter other values and press the appropriate buttons. After doing this, press 'Show Cookie'.

If you click 'Write Cookie' above, then you will get some information below. What you get might depend on what else is in your cookie!

We make changes with the cookie, as described previously, by using, for example:

<input type="button" value="Set Num Visits" name="B1"


The onclick creates a cookie with the name, 'numvisits', and the value derived from what you enter into the text box. The other buttons do something similar.

We write the cookie information in the text area by using the following function:

function writeCookie(){

document.form2.ta1.value="This is the whole cookie: "+document.cookie + "\n\n"+

"This is stuff extracted: \n"+

"Cookie Name="+GetCookie("Cookie Name")+"\n"+

"password = " + GetCookie("password") + "\n"+

"numvisits = " + GetCookie("numvisits")+"\n"


So we are basically using the functions to do things with cookies and calling them as needed.

The jsEditor contains a cookie wizard to put the basic code into your page. You can modify this code to create the effects you want. In addition to its many other features, you can use the jsEditor's knowledge base to explore the Math object. You can order the jsEditor online and download the full version immediately, so in a few minutes you could be using it to help you learn and develop scripts.

We have now reached a point where we have plaid with cookies, and can start doing some interesting stuff with them. The first thing we will do is to get the user name and remember it when they next visit the page.


Ken Ward's HTML Guide...