Go Back   CodingForums.com > :: Server side development > Java and JSP

Before you post, read our: Rules & Posting Guidelines

Closed Thread
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-25-2008, 06:19 PM   PM User | #1
ictoacu
New to the CF scene

 
Join Date: Apr 2008
Location: California
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
ictoacu is an unknown quantity at this point
Reading Data From Cookie

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....

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtmll/DTD/xhtmll-strict.dtd">
<html>
<head>
<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 }
</style>
<script type=text/javascript>
<!--HIDE FROM INCOMPATIBLE BROWSERS
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!");
						document.forms[0].password.focus();
					}
		}
function ensurePasswordConfirm () {
		if (!document.forms[0].password_confirm.focus()) {
				window.alert("You must confirm the password you entered!");
			document.forms[0].password_confirm.focus();
			}
}
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]);
	}
		
//STOP HIDING FROM INCOMPATIBLE BROWSERS -->
</script>
</head>
<body onload="getCookie();" id="docBody">
<h1>Kudler Fine Foods Customer Information Page</h2>
<form action="FormProcessor.html" method="get"
		enctype="application/x-www-form-urlencoded"
		onsubmit="return confirmSubmit();"
		onreset="return confirmReset();">
<table border="0" cellpadding="3" cellspacing="0">
		<tr>
			<td valign="top">
				<p>Name<br />
					<input type="text" name="name" size="50" />
				</p>
			
				<p>Address<br />
					<input type="text" name="address" size="50" onchange="setCookie();" />
				</p>				
				<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>
				<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>
				<p>Enter a password that you can use to<br /> 
						manage your subscription online:<br />
					<input type="password" name="password" size="50" 
						onchange="ensurePasswordConfirm();"/></p>
				<p>Type the password again to confrim it.<br />
					<input type="password" name="password_confirm" size="50"
						onchange="confirmPassword();" />
				</p>
				<p>
					<input type="submit" value="Submit Form" />
					<input type="reset" />
				</p>
				

			</td>
		</tr>
		
</form>				
</body>
</html>
ictoacu is offline  
Old 04-25-2008, 06:47 PM   PM User | #2
mjlorbet
Regular Coder

 
mjlorbet's Avatar
 
Join Date: Jan 2008
Location: Milwaukee, WI
Posts: 724
Thanks: 8
Thanked 96 Times in 95 Posts
mjlorbet will become famous soon enough
this is posted in the wrong forum, this is the java/jsp (java server pages) forum not the javascript forum
__________________
-Mike
"Want me to precludify him, like some kind of dispatcherator?... Can do!" -Bender
mjlorbet is offline  
Old 04-25-2008, 07:06 PM   PM User | #3
ictoacu
New to the CF scene

 
Join Date: Apr 2008
Location: California
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
ictoacu is an unknown quantity at this point
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....
ictoacu is offline  
Old 04-26-2008, 03:19 AM   PM User | #4
Aradon
Moderator-san


 
Aradon's Avatar
 
Join Date: Jun 2005
Location: USA
Posts: 734
Thanks: 0
Thanked 20 Times in 19 Posts
Aradon is on a distinguished road
Don't want to duplicate the thread, so closing.
__________________
"To iterate is human, to recurse divine." -L. Peter Deutsch
Aradon is offline  
Closed Thread

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:30 AM.


Advertisement
Log in to turn off these ads.