6 Replies - 3633 Views - Last Post: 26 January 2011 - 10:51 PM

#1 MrsE   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 06-September 10

Trouble creating cookie for form.

Posted 24 January 2011 - 02:44 PM

Hellp DIC!
It has been quite awhile since I have had to ask, but I am in a pickle and could use some help.
I have successfully completed the first two sections of my service request on my own, using w3cschools tutorials, etc., However the last SR is killing me...I am trying to create a cookie to let the user know they have already submitted the form. It doesn't seem to be creating the cookie, so I don't know if the separate HTML file will come up or not. I have been working on this for days, and can't figure out what I have done wrong, could someone please help? I am attaching the service request as well as the code for my main page and the two pages it should direct the user to.

Here is the service Request:

Quote

Service Request SR-kf-011

Customer Mailing List
Organization: Kudler Fine Foods
Locations: All
Requester: Yvonne Reynolds

Description of Request:
Add a page to the Internet site to collect demographic information for a customer mailing list.

Background of Request:
We want to collect customer demographic information in order to send out information to our
customers about sales and in-store events. We want to capture the customer's name, mailing
address, e-mail address and telephone number. Upon submission of the information, the customer
should be directed to another HTML page that acknowledges receipt of their information.
We just want to see a prototype at this stage, so formatting to match the rest of the Kudler Internet
site is not required.

Expected Results/Impact when completed:
An HTML page that contains a form to collect customer
1. demographic data.
2. An HTML acknowledgment page.

Change Requests

Change Request #1
Requestor: Yvonne Reynolds
Modify the prototype form page to verify that all required information has been submitted.
Customers should be required to provide their name and either their mailing address or their email
address. Use Javascript to verify that all required fields have been filled. Prompt users for
missing information. When all required fields have been filled, the user should be directed to the
acknowledgment page.

Change Request #2
Requestor: Yvonne Reynolds
Modify the prototype form page so that when the Javascript function has verified that all of the
required fields have been filled, a cookie is added to the user's computer. If the same user
attempts to fill out the form a second time, the user will be directed to a separate HTML page
advising them that they have already submitted the form.


Here is my main form page. I have tried to write in the cookie, but the form still just verifies and forwards to confirmation page, It doesn't create the cookie as I expected it would.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"  lang="en" xml:lang="en" >

<head>
    <title>Phoenix: Kudler Fine Foods</title>
	
		
		
	<script src="/afm214/shared/scripts/1.35.24/assignment.js" language="Javascript" type="text/javascript"></script>
	
		
	<link href="https://assets.phoenix.edu/0.2/core/3.4/css/appElements.css?olsVersion=3.4-1.35.24" rel="stylesheet" type="text/css"/>
	<link href="https://assets.phoenix.edu/0.2/projects/classroom/3.4/assignments/css/appElements.css?olsVersion=3.4-1.35.24" rel="stylesheet" type="text/css"/>
	
	<script language="javascript" src="https://assets.phoenix.edu/0.2/jsfw/jquery/jquery-ui-1.6/jquery-1.2.6.min.js?olsVersion=3.4-1.35.24" type="text/javascript"></script>

	
	<script src="/afm214/shared/scripts/lang/en/1.35.24/globalvariables.js" language="Javascript" type="text/javascript"></script>	
    <style type="text/css">
html {
background-color:#ffffff;


}
body {
font-family:Arial,Helvetica,sans-serif;
font-size:13px;
font-size-adjust:none;
font-style:normal;
font-weight:normal;
line-height:1.231;

}
}</style>
    	<script src="/afm214/shared/scripts/base.js" language="Javascript" type="text/javascript"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<style type="text/css">
<!--
.style3 {color: #BE9DBD; font-weight: bold; }
.style5 {color: #BE9DBD}
a {color: #BE9DBD}
.style6 {
	font-size: 14px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style8 {color: #0033FF}
.style11 {font-size: 24px}
.style12 {font-size: 18px}
-->
</style>

<script language="javascript">
	function rollOn(i) {
		document.getElementById(i).style.color = "red";
	}
	
	function rollOff(i) {
		document.getElementById(i).style.color = "#BE9DBD";
	}
function validateInformation() {
	if (validateForm() == false)
		return false;
	if (cookieInformationExists() == true) {
		window.location = "formAlreadyFiled.html";

	}
	else {
		setCookie();
		return true;
		return false;
	}
	return false;
}
function cookieInformationExists() {
	if (document.cookie != "") {
		splitCookie = document.cookie.split("; ");
		name = unescape(splitCookie[0].split("=")[1]);
		if (name == "") {
			return false;
		}
		else {
			if (name!=kudler.name.value)
				return false;
			return true;
		}
	}
	else {
		return false;
	}
	return false;
}
function setCookie() {
	var expiresDate = new Date();
	expiresDate.setMonth(expiresDate.getMonth() + 6);
	document.cookie = encodeURI("name="+document.forms[0].name.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("StreetAddress="+document.forms[0].address.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("City="+document.forms[0].city.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("State="+document.forms[0].state.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("PostalCode="+document.forms[0].zip.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("Telephone="+document.forms[0].areacode.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("EmailAddress="+document.forms[0].email.value)+";expires="+expiresDate.toUTCString();

	return true;
}

function validateForm()

{
var x=document.forms["input"]["name"].value
if (x==null || x=="")
  {
  alert("Your name must be filled in");
  return false;
  }

var x=document.forms["input"]["StreetAddress"].value
if (x==null || x=="")
	{
	alert("Please provide your street address");
	return false;
	}
	
var x=document.forms["input"]["City"].value
if (x==null || x=="")
	{
	alert("Please provide your city");
	return false;
	}

var x=document.forms["input"]["State"].value
if (x==null || x=="")
	{
	alert("Please provide your state");
	return false;
	}
	
var x=document.forms["input"]["PostalCode"].value
if (x==null || x=="")
	{
	alert("Please provide your postal code");
	return false;
	}
var x=document.forms["input"]["EmailAddress"].value
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
  alert("Please provide a valid e-mail address");
  return false;
  }
 

}

	
</script>
</head>

	<body onload="">

<table width="100%" border="0" cellspacing="0" cellpadding="4">
  <tr align="center">
    <td colspan="6" bgcolor="#000000"><img src="Kudler-food-blk.gif" alt="Kudler Fine Foods Logo" width="275" height="146"></td>
  </tr>
  <tr align="center" bgcolor="#000000">
    <td width="20%"><a href="Index.htm" onmouseover="javascript:rollOn('bHome')" onmouseout="javascript:rollOff('bHome')"><span id="bHome" class="style3">Home</span></a></td>
	<td width="16%"><a href="Bakery.htm" onmouseover="javascript:rollOn('bBakery')" onmouseout="javascript:rollOff('bBakery')"><span id="bBakery" class="style3">Bakery</span></a></td>
    <td width="16%"><a href="Meat.htm" onmouseover="javascript:rollOn('bMeat')" onmouseout="javascript:rollOff('bMeat')"><span id="bMeat" class="style3">Meat &amp; Seafood</span></a></td>
    <td width="16%"><a href="Produce.htm" onmouseover="javascript:rollOn('bProduce')" onmouseout="javascript:rollOff('bProduce')"><span id="bProduce" class="style3">Produce</span></a></td>
    <td width="16%"><a href="Cheese.htm" onmouseover="javascript:rollOn('bCheese')" onmouseout="javascript:rollOff('bCheese')"><span id="bCheese" class="style3">Cheese &amp; Dairy </span></a></td>
    <td width="16%"><a href="Wine.htm" onmouseover="javascript:rollOn('bWine')" onmouseout="javascript:rollOff('bWine')"><span id="bWine" class="style3">Wine</span></a></td>
  </tr>
  <tr>
    <td bgcolor="#000000">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#000000"><p class="style5"><strong>Hours</strong><br>
      <u>Mon. - Sat.</u><br>
      10 - 6<br>
      <u>Sun.</u><br>
      11 - 4
    </p>
    </td>
    <td align="center" colspan="5" rowspan="2" valign="top" bgcolor="#C69C98"><p class="style6"><span class="style11">Kudler Fine Foods</span><br>
        <form name="input" action="html_form_action.asp" onsubmit="return validateForm()" method="get">
		Name: <input type="text" name="name" value=""/ ><br/>
		Street Address: <input type="text" name="StreetAddress" value=""/><br />
		City: <input type="text" name="City" value=""/><br />
		State: <input type="text" name="State" value=""/><br />
		Postal Code: <input type="text" name="PostalCode" value="" /><br />
		Telephone: <input type="text" name="Telephone" value="" /><br />
		Email Address: <input type="text" name="EmailAddress" value="" /><br />

<input type="submit" value="Submit">
</form>
      
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#000000"><p class="style5"><strong>Locations</strong><br>
      <a href="LaJollaMap.htm" onmouseover="javascript:rollOn('bLaJolla')" onmouseout="javascript:rollOff('bLaJolla')"><span id="bLaJolla">La Jolla</span></a><br>
      <span id="bDelMar">Del Mar</span><br>
      <a href="EncinitasMap.htm" onmouseover="javascript:rollOn('bEncinitas')" onmouseout="javascript:rollOff('bEncinitas')"><span id="bEncinitas">Encinitas</span></a>
    </p>
    </td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#000000">&nbsp;</td>
    <td align="center" colspan="5" valign="top" bgcolor="#C69C98">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="6" class="style5" bgcolor="#000000"><div align="center">
      Copyright &copy; 2007 by Apollo Group, Inc.
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<!--Google Analytics Code -->
	<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
	</script>
	<script type="text/javascript">
		_uacct = "UA-1768756-3";
		urchinTracker();
	</script>

</body>
</html>



When the form is filled out the first time, and it is submitted the user is re-directed to this confirmation page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Kudler Fine Foods</title>
<style type="text/css">
<!--
.style3 {color: #BE9DBD; font-weight: bold; }
.style5 {color: #BE9DBD}
a {color: #BE9DBD}
.style6 {
	font-size: 14px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style8 {color: #0033FF}
.style11 {font-size: 24px}
.style12 {font-size: 18px}
-->
</style>

<script language="javascript">
	function rollOn(i) {
		document.getElementById(i).style.color = "red";
	}
	
	function rollOff(i) {
		document.getElementById(i).style.color = "#BE9DBD";
	}
</script>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
  <tr align="center">
    <td colspan="6" bgcolor="#000000"><img src="Kudler-food-blk.gif" alt="Kudler Fine Foods Logo" width="275" height="146"></td>
  </tr>
  <tr align="center" bgcolor="#000000">
    <td width="20%"><a href="Index.htm" onmouseover="javascript:rollOn('bHome')" onmouseout="javascript:rollOff('bHome')"><span id="bHome" class="style3">Home</span></a></td>
	<td width="16%"><a href="Bakery.htm" onmouseover="javascript:rollOn('bBakery')" onmouseout="javascript:rollOff('bBakery')"><span id="bBakery" class="style3">Bakery</span></a></td>
    <td width="16%"><a href="Meat.htm" onmouseover="javascript:rollOn('bMeat')" onmouseout="javascript:rollOff('bMeat')"><span id="bMeat" class="style3">Meat &amp; Seafood</span></a></td>
    <td width="16%"><a href="Produce.htm" onmouseover="javascript:rollOn('bProduce')" onmouseout="javascript:rollOff('bProduce')"><span id="bProduce" class="style3">Produce</span></a></td>
    <td width="16%"><a href="Cheese.htm" onmouseover="javascript:rollOn('bCheese')" onmouseout="javascript:rollOff('bCheese')"><span id="bCheese" class="style3">Cheese &amp; Dairy </span></a></td>
    <td width="16%"><a href="Wine.htm" onmouseover="javascript:rollOn('bWine')" onmouseout="javascript:rollOff('bWine')"><span id="bWine" class="style3">Wine</span></a></td>
  </tr>
  <tr>
    <td bgcolor="#000000">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#000000"><p class="style5"><strong>Hours</strong><br>
      <u>Mon. - Sat.</u><br>
      10 - 6<br>
      <u>Sun.</u><br>
      11 - 4
    </p>
    </td>
    <td align="center" colspan="5" rowspan="2" valign="top" bgcolor="#C69C98"><p class="style6"><span class="style11">Kudler Fine Foods</span><br>
        <span class="style12">THANK YOU</span><br>
      Your contact information has been submitted.<br>
      Please Visit Kudler Fine Foods Again!<br>
      </p>
      
	 </td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#000000"><p class="style5"><strong>Locations</strong><br>
      <a href="LaJollaMap.htm" onmouseover="javascript:rollOn('bLaJolla')" onmouseout="javascript:rollOff('bLaJolla')"><span id="bLaJolla">La Jolla</span></a><br>
      <span id="bDelMar">Del Mar</span><br>
      <a href="EncinitasMap.htm" onmouseover="javascript:rollOn('bEncinitas')" onmouseout="javascript:rollOff('bEncinitas')"><span id="bEncinitas">Encinitas</span></a>
    </p>
    </td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#000000">&nbsp;</td>
    <td align="center" colspan="5" valign="top" bgcolor="#C69C98">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="6" class="style5" bgcolor="#000000"><div align="center">
      Copyright &copy; 2007 by Apollo Group, Inc.
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<!--Google Analytics Code -->
	<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
	</script>
	<script type="text/javascript">
		_uacct = "UA-1768756-3";
		urchinTracker();
	</script>
	</body>
</html>



And if the same user tries to submit the form again this is the page they should be re-directed to:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Kudler Fine Foods</title>
<style type="text/css">
<!--
.style3 {color: #BE9DBD; font-weight: bold; }
.style5 {color: #BE9DBD}
a {color: #BE9DBD}
.style6 {
	font-size: 14px;
	font-family: Verdana, Arial, Helvetica, sans-serif;
}
.style8 {color: #0033FF}
.style11 {font-size: 24px}
.style12 {font-size: 18px}
-->
</style>

<script language="javascript">
	function rollOn(i) {
		document.getElementById(i).style.color = "red";
	}
	
	function rollOff(i) {
		document.getElementById(i).style.color = "#BE9DBD";
	}
</script>
</head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="4">
  <tr align="center">
    <td colspan="6" bgcolor="#000000"><img src="Kudler-food-blk.gif" alt="Kudler Fine Foods Logo" width="275" height="146"></td>
  </tr>
  <tr align="center" bgcolor="#000000">
    <td width="20%"><a href="Index.htm" onmouseover="javascript:rollOn('bHome')" onmouseout="javascript:rollOff('bHome')"><span id="bHome" class="style3">Home</span></a></td>
	<td width="16%"><a href="Bakery.htm" onmouseover="javascript:rollOn('bBakery')" onmouseout="javascript:rollOff('bBakery')"><span id="bBakery" class="style3">Bakery</span></a></td>
    <td width="16%"><a href="Meat.htm" onmouseover="javascript:rollOn('bMeat')" onmouseout="javascript:rollOff('bMeat')"><span id="bMeat" class="style3">Meat &amp; Seafood</span></a></td>
    <td width="16%"><a href="Produce.htm" onmouseover="javascript:rollOn('bProduce')" onmouseout="javascript:rollOff('bProduce')"><span id="bProduce" class="style3">Produce</span></a></td>
    <td width="16%"><a href="Cheese.htm" onmouseover="javascript:rollOn('bCheese')" onmouseout="javascript:rollOff('bCheese')"><span id="bCheese" class="style3">Cheese &amp; Dairy </span></a></td>
    <td width="16%"><a href="Wine.htm" onmouseover="javascript:rollOn('bWine')" onmouseout="javascript:rollOff('bWine')"><span id="bWine" class="style3">Wine</span></a></td>
  </tr>
  <tr>
    <td bgcolor="#000000">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
    <td bgcolor="#C69C98">&nbsp;</td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#000000"><p class="style5"><strong>Hours</strong><br>
      <u>Mon. - Sat.</u><br>
      10 - 6<br>
      <u>Sun.</u><br>
      11 - 4
    </p>
    </td>
    <td align="center" colspan="5" rowspan="2" valign="top" bgcolor="#C69C98"><p class="style6"><span class="style11">Kudler Fine Foods</span><br>
        <span class="style12">THANK YOU</span><br>
      <h3>You have already submitted this form.</h3><br>
      Please Visit Kudler Fine Foods Again!<br>
      </p>
      
	 </td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#000000"><p class="style5"><strong>Locations</strong><br>
      <a href="LaJollaMap.htm" onmouseover="javascript:rollOn('bLaJolla')" onmouseout="javascript:rollOff('bLaJolla')"><span id="bLaJolla">La Jolla</span></a><br>
      <span id="bDelMar">Del Mar</span><br>
      <a href="EncinitasMap.htm" onmouseover="javascript:rollOn('bEncinitas')" onmouseout="javascript:rollOff('bEncinitas')"><span id="bEncinitas">Encinitas</span></a>
    </p>
    </td>
  </tr>
  <tr>
    <td align="center" valign="top" bgcolor="#000000">&nbsp;</td>
    <td align="center" colspan="5" valign="top" bgcolor="#C69C98">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="6" class="style5" bgcolor="#000000"><div align="center">
      Copyright &copy; 2007 by Apollo Group, Inc.
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
<!--Google Analytics Code -->
	<script src="https://ssl.google-analytics.com/urchin.js" type="text/javascript">
	</script>
	<script type="text/javascript">
		_uacct = "UA-1768756-3";
		urchinTracker();
	</script>
	</body>
</html>



If someone has the time to just give me a hint or help me get this figure out, I really thought I would have got it by now, and with my deadline coming in 9 hours I am getting a little nervous. Any help I can get will be greatly appreciated!

Is This A Good Question/Topic? 0
  • +

Replies To: Trouble creating cookie for form.

#2 MrsE   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 06-September 10

Re: Trouble creating cookie for form.

Posted 24 January 2011 - 02:55 PM

BTW...that was supposed to read HELLO DIC, not Hellp...lmao...I am not that great at this but I won't wine and beg too much...LOL
Was This Post Helpful? 0
  • +
  • -

#3 forest51690   User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: Trouble creating cookie for form.

Posted 25 January 2011 - 04:57 PM

From what I can see, the ValidateForm function checks if the form is valid, but it does not set a cookie. From reading the specification, it seems that it should set a cookie on success.
Was This Post Helpful? 0
  • +
  • -

#4 MrsE   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 06-September 10

Re: Trouble creating cookie for form.

Posted 26 January 2011 - 07:33 AM

View Postforest51690, on 25 January 2011 - 04:57 PM, said:

From what I can see, the ValidateForm function checks if the form is valid, but it does not set a cookie. From reading the specification, it seems that it should set a cookie on success.


That is my problem. Whenever I tried to put the cookie code in the validateForm function the rest of my form stops functioning properly. I have the least helpful instructor on earth, and was really just trying to figure out how to put the code I have together properly so the cookie will be created when the form is submitted.....I have already submitted the assignment, but I know the only feedback I will get is a point reduction with no explanation....Hopefully I will get it figured out on my own soon. I appreciate that you took the time to look at my code and reply to me. Thank you.
Was This Post Helpful? 0
  • +
  • -

#5 forest51690   User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: Trouble creating cookie for form.

Posted 26 January 2011 - 11:21 AM

If you want, you can post the ValidateForm function, including the document cookie code and I can try to see what's wrong with it.
Was This Post Helpful? 0
  • +
  • -

#6 MrsE   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 35
  • Joined: 06-September 10

Re: Trouble creating cookie for form.

Posted 26 January 2011 - 02:20 PM

View Postforest51690, on 26 January 2011 - 11:21 AM, said:

If you want, you can post the ValidateForm function, including the document cookie code and I can try to see what's wrong with it.


Here is the code I wrote to try to create the cookie:
function validateInformation() {
	if (validateForm() == false)
		return false;
	if (cookieInformationExists() == true) {
		window.location = "formAlreadyFiled.html";

	}
	else {
		setCookie();
		return true;
		return false;
	}
	return false;
}
function cookieInformationExists() {
	if (document.cookie != "") {
		splitCookie = document.cookie.split("; ");
		name = unescape(splitCookie[0].split("=")[1]);
		if (name == "") {
			return false;
		}
		else {
			if (name!=kudler.name.value)
				return false;
			return true;
		}
	}
	else {
		return false;
	}
	return false;
}
function setCookie() {
	var expiresDate = new Date();
	expiresDate.setMonth(expiresDate.getMonth() + 6);
	document.cookie = encodeURI("name="+document.forms[0].name.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("StreetAddress="+document.forms[0].address.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("City="+document.forms[0].city.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("State="+document.forms[0].state.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("PostalCode="+document.forms[0].postalcode.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("Telephone="+document.forms[0].telephone.value)+";expires="+expiresDate.toUTCString();
	document.cookie = encodeURI("EmailAddress="+document.forms[0].emailaddress.value)+";expires="+expiresDate.toUTCString();

	return true;
}


Here is the code for my validateForm function:
function validateForm()

{
var x=document.forms["input"]["name"].value
if (x==null || x=="")
  {
  alert("Your name must be filled in");
  return false;
  }

var x=document.forms["input"]["StreetAddress"].value
if (x==null || x=="")
	{
	alert("Please provide your street address");
	return false;
	}
	
var x=document.forms["input"]["City"].value
if (x==null || x=="")
	{
	alert("Please provide your city");
	return false;
	}

var x=document.forms["input"]["State"].value
if (x==null || x=="")
	{
	alert("Please provide your state");
	return false;
	}
	
var x=document.forms["input"]["PostalCode"].value
if (x==null || x=="")
	{
	alert("Please provide your postal code");
	return false;
	}
var x=document.forms["input"]["EmailAddress"].value
var atpos=x.indexOf("@");
var dotpos=x.lastIndexOf(".");
if (atpos<1 || dotpos<atpos+2 || dotpos+2>=x.length)
  {
  alert("Please provide a valid e-mail address");
  return false;
  }
 

}



Here is my form code as well:
 <form name="input" action="html_form_action.asp" onsubmit="return validateForm()" method="get">
		Name: <input type="text" name="name" value=""/ ><br/>
		Street Address: <input type="text" name="StreetAddress" value=""/><br />
		City: <input type="text" name="City" value=""/><br />
		State: <input type="text" name="State" value=""/><br />
		Postal Code: <input type="text" name="PostalCode" value="" /><br />
		Telephone: <input type="text" name="Telephone" value="" /><br />
		Email Address: <input type="text" name="EmailAddress" value="" /><br />

<input type="submit" value="Submit">
</form>



I appreciate your help, and your time. It seems like sometimes instructors think that students all just want the "Piece of paper"...and forget some of us are really trying to learn....lol. Thanks again.
Was This Post Helpful? 0
  • +
  • -

#7 forest51690   User is offline

  • D.I.C Regular
  • member icon

Reputation: 58
  • View blog
  • Posts: 340
  • Joined: 20-March 09

Re: Trouble creating cookie for form.

Posted 26 January 2011 - 10:51 PM

Well the code looks well-formed. Usually when there's a JS syntax error, the code just doesn't run at all. Is that what happens? And have you checked the error console of your browser?

On line 26, I saw a reference to kudler.name.value. What's that?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1