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>

merchant.js

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 = "";

Recommended Answers

All 12 Replies

making the question I shall ask a fair question.

So what's your question. You never actually asked a question.

On another note, when posting "blocks" of code, wrap them in [ CODE ] and [/ CODE ] (without the spaces around the word "CODE" - I used spaces so you can see the needed syntax). Alternatively, you can press on the "button" labeled CODE on the editor. Here's what it would look like if you do it right:

var str="hello";
alert( str );

To write inline-code (highlight a single code statement) use [ icode ] and [/ icode ]. Notice how alert("hello"); is highlighted when you use icode.

The question is "How do I correct the code to make the errors go away?". The problem spots are so marked with frowney faces.

I regard hielo's non-responsive response as an attempt to bully a newbie. I am actually an accomplished Computer Programmer, but I am having a time of it getting up to speed on JavaScript and the DaniWeb Editor. I satated that I am working a Chapter 9 problem in a difficult textbook, and I deserve a far better answer than that newbie's "Hello World" response. I feel that the problem code was well marked and documented by the Frownies and comments.

I feel I have asked a fair question and have been snubbed. What is my recourse?

I regard hielo's non-responsive response as an attempt to bully a newbie.

I'm sorry you feel that way, but nothing in hielo's post constitutes bullying. Your use of code tags made the code more difficult to follow (for which he suggested a fix), and frowny faces embedded in the code isn't exactly a common idiom to mark problem areas. In fact, outside of code tags, the very nature of some languages can create unintentional emoticons, so it's not unreasonable to interpret your original post as containing no real question.

BTW, since you are using:

<form name="market" action="merchant_acct.htm" onsubmit="return handleAll()" method="post">

typically web servers don't process files that end in ".htm" (or ".html") dynamically. Meaning, said files are treated as "static" files. If that is the case with your server configuration, when you submit a POST request (which your form is currently doing), you will most likely get a 405 error - which basically translates to "this server is not configured to allow POST requests to files ending in .htm").

If you notice this problem, change your form to

method="get"

Much Better!

The syntax update could also explain why both ".toUTCString()" and ".toGMTString() " failed.

Further, the text I am using is notorious for errors. I want to work every problem in the book for practice.

Regards

why both ".toUTCString()" and ".toGMTString() " failed.

OK, I see. On the posted code expdate is a number object, not a date object. The .toGMTString() and .toUTCString() are methods of a date object. So you need to use
that numeric value to create a date object. So change expdate = (currDate.getTime()+ 3652425 * 24 * 60 * 60 ); to expdate = new Date(currDate.getTime()+ 3652425 * 24 * 60 * 60 ); FYI: The previous suggestion still stands - going forward, try not to use the decrated method .toGMTString() and use .toUTCString() instead.

OK, I see. On the posted code expdate is a number object, not a date object. The .toGMTString() and .toUTCString() are methods of a date object. So you need to use
that numeric value to create a date object. So change expdate = (currDate.getTime()+ 3652425 * 24 * 60 * 60 ); to expdate = new Date(currDate.getTime()+ 3652425 * 24 * 60 * 60 ); FYI: The previous suggestion still stands - going forward, try not to use the decrated method .toGMTString() and use .toUTCString() instead.

I'm going to try this after I get back from Easter Vacation. Let's close this out for now and I'll get back to you next week. Thanks!

try not to use the decrated method

I meant to write "deprecated".

Does anyone have the final coding for this JAVAcript

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.