View Full Version : Reading Data From Cookie

04-25-2008, 07:19 PM
I have created a basic form in JavaScript that asks for user data, I then store that data in a cookie. What I need is if the user comes back to the page and fills in the same data I want to re-direct the user to another page stating that has already been entered. Right now I know I am able to read the cookie because I put in a test message on page load to show me the data. I just don't know how to compare the data in the cookie with the data entered and then re-direct if the data matches....

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<title>Kudler Fine Foods Customer Form</title>
<style type="text/css">
body { font-family: "Trebuchet MS", Arial, Helvetica, sans-serif, serif}
h2 { font-size: 1.2em }
<script type=text/javascript>
function checkForNumber(fieldValue) {
var numberCheck = isNaN(fieldValue);
if (numberCheck == true) {
window.alert("You must enter a numeric value!");
return false;
function confirmPassword() {
if (document.forms[0].password.value !=
document.forms[0].password_confirm.value) {
window.alert("You did not enter the same password!");
function ensurePasswordConfirm () {
if (!document.forms[0].password_confirm.focus()) {
window.alert("You must confirm the password you entered!");
function confirmSubmit() {
if (document.forms[0].name.value == "") {
window.alert("You must enter your name!!");
return false;
if (document.forms[0].address.value == ""
|| document.forms[0].email_address.value == "") {
window.alert("You must enter your address or email address!!");
return false;
function confirmReset () {
var resetForm = window.confirm("Are you sure you want to reset the form?");
if (resetForm == true)
return true;
return false;
function setCookie () {
var expiresDate = new Date();
expiresDate.setFullYear(expiresDate.getFullYear() + 1);
document.cookie = encodeURI ("name="
+ document.forms[0].name.value) + "; expires="
+ expiresDate.toUTCString ();
document.cookie = encodeURI ("address="
+ document.forms[0].address.value) + "; expires="
+ expiresDate.toUTCString ();
function getCookie () {
var getData = decodeURI(document.cookie);
var data = getData.split("; ")
var name = data[0].split("=");
var address = data[1].split("=");
window.alert("Welcome " + name[1] + " Your address is " + address[1]);

<body onload="getCookie();" id="docBody">
<h1>Kudler Fine Foods Customer Information Page</h2>
<form action="FormProcessor.html" method="get"
onsubmit="return confirmSubmit();"
onreset="return confirmReset();">
<table border="0" cellpadding="3" cellspacing="0">
<td valign="top">
<p>Name<br />
<input type="text" name="name" size="50" />

<p>Address<br />
<input type="text" name="address" size="50" onchange="setCookie();" />
<p>City, State, Zip<br />
<input type="text" name="city" size="34" />
<input type="text" name="state" size="2" maxlength="2" />
<input type="text" name="zip" size="5" maxlength="5" onchange="return checkForNumber(this.value);" />
<p>Telephone<br />
(<input type="text" name="area" size="3" maxlength="3" />) <input
type="text" name="exchange" size="3" maxlength="3" />
<input type="text" name="phone" size="4" maxlength="4" onchange="return checkForNumber(this.value);" /></p>
<p>E-Mail Address</br />
<input type="text" name="email_address" size="70" />
<p>Enter a password that you can use to<br />
manage your subscription online:<br />
<input type="password" name="password" size="50"
<p>Type the password again to confrim it.<br />
<input type="password" name="password_confirm" size="50"
onchange="confirmPassword();" />
<input type="submit" value="Submit Form" />
<input type="reset" />



04-25-2008, 07:47 PM
this is posted in the wrong forum, this is the java/jsp (java server pages) forum not the javascript forum

04-25-2008, 08:06 PM
oops you're right I posted it in the correct forum now, sorry about that, I don't see an option to delete the post....

04-26-2008, 04:19 AM
Don't want to duplicate the thread, so closing.