The following problem comes from an old JavaScript Textbook, JavaScript – First Edition, by Patrick Carey and Frank Canovatchel. This problem is not used in the Second Edition, making the question I shall ask a fair question. The problem is Case Problem 2, Chapter 9, pages 519-20. Here are the files:
merchant.htm:
<html>
<head>
<script type="text/javascript" src="merchant.js"></script>
<title>Merchants Market</title>
</head>
<body onload="checkAcct()">
<h2>Account Processing Page</h2>
<div id="registration_form">
<form name="market" action="merchant_acct.htm" onsubmit="return handleAll()" method="post">
<table>
<tr>
<td align="right">First Name:</td>
<td><input name="first" size="25" /></td>
</tr>
<tr>
<td align="right">Last Name:</td>
<td><input name="last" size="25" /></td>
</tr>
<tr>
<td align="right">Mailing Address:</td>
<td><input name="add" size="30" /></td>
</tr>
<tr>
<td align="right">E-Mail Address:</td>
<td><input name="em" size="35" /></td>
</tr>
<tr>
<td align="right">Bank Name:</td>
<td><input name="bank" size="25" /></td>
</tr>
<tr>
<td align="right">Checking Account Number:</td>
<td><input name="acct_num" size="16" maxlength="16"/></td>
</tr>
<tr>
<td align="right">Routing Number:</td>
<td><input name="r_num" size="9" maxlength="9"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="Process Request" />
<input type="reset" value="Clear Form" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>
merchant_acct.htm
<html>
<head>
<script type="text/javascript" src="merchant.js"></script>
<link rel="stylesheet" type="text/css" href="merchant.css" />
<title>Merchants Market - Account</title>
</head>
<body>
<h2>Account Verification Page</h2>
<div id="form1">
<form name="feedback" >
<table>
<tr>
<td align="right" class="table_text">First Name:</td>
<td class="table_text"></td>
</tr>
<tr>
<td align="right" class="table_text">Last Name:</td>
<td class="table_text"></td>
</tr>
<tr>
<td align="right" class="table_text">Mailing Address:</td>
<td class="table_text"></td>
</tr>
<tr>
<td align="right" class="table_text">E-Mail Address:</td>
<td class="table_text"></td>
</tr>
<tr>
<td align="right" class="table_text">Bank Name:</td>
<td class="table_text"></td>
</tr>
<tr>
<td align="right" class="table_text">Checking Account Number:</td>
<td class="table_text"></td>
</tr>
<tr>
<td align="right" class="table_text">Routing Number:</td>
<td class="table_text"></td>
</tr>
</table>
</form>
</div>
</body>
</html>
function findCookie(val){
var cookie = null;
var findVal = val + "=";
var dc = document.cookie;
if (dc.length > 0)
{
var start = dc.indexOf(findVal);
if (start >= 0)
{
start += findVal.length;
lastVal = dc.indexOf(";", start);
if (lastVal == -1)
{
lastVal = dc.length;
}
cookie = (dc.substring(start, lastVal));
}
}
return unescape(cookie);
}
reg = findCookie("reg")
function checkAcct(){
if(reg !=null)
{
alert("You have already registered with Merchant's Market. Please log in using your Username and Password.");
return false;
}
}
function handleAll(){
/*
Here is our second stop, the retrieval or building of a cookie
*/
first=document.market.first.value;
last = document.market.last.value;
em=document.market.em.value;
acct_num=document.market.acct_num.value;
r_num=document.market.r_num.value;
if((first== "")||(last == "")||(em == "")||(acct_num == "")||(r_num == ""))
{
alert("Please be sure to fill out all fields on this form.")
return false;
document.market.focus();
}
else
{
buildCookies(first,last,em,acct_num,r_num)
/*
Here we dispach to the cookie builder
*/
}
}
currDate = new Date();
expdate = (currDate.getTime()+ 3652425 * 24 * 60 * 60 );
function newCookie(){
document.cookie = "reg = registered; expired ="+expdate.toGMTString();
}
function buildCookies(first,last,em,acct_num,r_num){
// Here's where the problems are. :icon_frown:
document.cookie = "first="+first+"; expires = "+expdate.toGMTString();
// Error Status: Object doesn't support this property or method :@
document.cookie = "last="+last+"; expires = "+expdate.toGMTString();
// Error Status: Object doesn't support this property or method :@
document.cookie = "em="+em+"; expires ="+expdate.toGMTString();
// Error Status: Object doesn't support this property or method :@
document.cookie = "acct_num="+acct_num+"; expires = "+expdate.toGMTString();
// Error Status: Object doesn't support this property or method :@
document.cookie = "r_num="+r_num+"; expires = "+expdate.toGMTString();
// Error Status: Object doesn't support this property or method :@
window.location = "merchant_acct.htm";
}
function findCookie(val){
var cookie = null;
var findVal = val + "=";
var dc = document.cookie;
if (dc.length>0) {
var start = dc.indexOf(findVal);
if( start >= 0) {
start += findVal.length;
lastVal = dc.indexOf(";", start);
if(lastVal == -1){
lastVal = dc.length;
}
cookie = (dc.substring(start,lastVal));
} else {
return cookie;
}
}
return cookie;
}
var first = findCookie("first");
var last = findCookie("last");
var em = findCookie("em");
var acct_num = findCookie("acct_num");
var r_num = findCookie("r_num");
var add = "";
var table_text = "";