Passing Parameters using Cookies - Page 2

Okay, here is a new form with the name that you typed in on the previous page already filled in. To keep things simple I have left everything out of the form except this one field.

In this instance the entire form is created using document.write statements from within a Javascript contained in the <body> of the page. The code for the above form is as follows:

document.write('<form name="myform"><div class="centre">');
document.write('Your First Name <input type="text" name="requiredfirstname" value="');
var firstname = get_cookie('pass');

document.write('" size="25" maxlength="40" /></div></form>');

As you can see we simply get the cookie value and output it to the appropriate place in our page code. In this instance we assign it as the value of our input field but it is just as easy to include it anywhere in the page.

So there you are, a simple example of passing a form field between pages using a cookie. This can easily be expanded to pass as many fields as you require by substituting the array processing from the Cookie Toolbox for the set and get calls used in this example.


This article written by Stephen Chapman, Felgall Pty Ltd.

go to top

FaceBook Follow
Twitter Follow