PDA

View Full Version : Shopping Cart debugging question


eZar
04-17-2003, 05:58 AM
I am learning Java/Javascript within a project at the moment; however, I've
run across a problem. Currently, I'm using Macromedia DreamWeaver and MS
Frontpage 2002. When I preview the script in IE6, I get an error on line 129 (in the Order.js) stating that the "myForm.itemdesc" is null or not an object, but
I have no clue how to remedy this. Here is the script I have that concerns
the issue.

</script>
<form name="menu">
<input type="button" name="button" onClick="buttonText(value);" value="View
Basket / Check Out" />
</form>
</span>
<div id="layer1" style="position:absolute; bottom:333; right:289; width:400;
height:-1200; visibility:hidden">
<html>
<head>
<title>Shopping_Cart_Page</title>
<script type="text/javascript" src=scripts/Cart.js>
</script>
<script type="text/javascript" src=scripts/Order.js>
</script>
<script type="text/javascript" src=scripts/Basket.js>
</script>
</head>
<body>
<p>SHOPPING CART</p>
</body>
</html>
</div>

And here is the "Order.js"

var myForm=document.forms[0];
var taxRate=790; //enter no decimal, 2 places assumed; i.e., 9%=900
var sub2=0;
var tax=0;
var total=0;
desc = new Array(number); //product descriptions
prices = new Array(number); //product prices as integers no decimal
shipping = new Array(number);
prodTotals = new Array(number); //line item totals
//
desc[0] = "item";
desc[1] = "SONY PS 2 WITH GT3";
desc[2] = "SONY PS 2";
desc[3] = "GRAN TURISMO 3 GT3 FOR THE PS2";
desc[4] = "SONY PS ONE";
desc[5] = "PALM M505";
desc[6] = "PALM M100";
//
prices[0] = 1995;
prices[1] = 36995;
prices[2] = 33995;
prices[3] = 5995;
prices[4] = 13995;
prices[5] = 48995;
prices[6] = 16995;
//
shipping[0] = 1995;
shipping[1] = 1995;
shipping[2] = 1995;
shipping[3] = 1995;
shipping[4] = 1995;
shipping[5] = 1995;
shipping[6] = 1995;
//
function displayOrder() {
printTableHeadings();
for (var i=0 ; i<number ; i++){
if (qty[i]>0)
printRow();
else
printHiddenRow();
}
printSubtotal();
}
//
function convertPrice(price) {
var priceString = price + "x";
var length = priceString.indexOf("x");
while (length<3) {
priceString = "0" + priceString;
length = priceString.indexOf("x");
}
var decString = "$" + priceString.substring(0, length-2) + "." +
priceString.substring(length - 2, length);
return decString;
}
//
function printTableHeadings() {
document.write('<table border="1" width="100%" cellpadding="2"
bgcolor="beige">');
document.write('<tr>');
document.write('<td width="55%"><p
align="center"><b>Description</b></td>');
document.write('<td width="15%"><p align="center"><b>Quantity</b></td>');
document.write('<td width="15%"><p align="center"><b>Price
Each</b></td>');
document.write('<td width="15%"><p align="center"><b>Total</b></td>');
document.write('</tr>');
}
//
function printRow() {
document.write('<form>');
document.write('<tr>');
document.write('<td width="55%"><p align="left">');
document.write('<input disabled type="text" name="itemDesc" size="35"
value=""></td>');
document.write('<td width="15%"><p align="right">');
document.write('<input type="text" name="itemQty" size="4" value=""
language="javascript" onChange="updateTable();"></td>');
document.write('<td width="15%"><p align="right">');
document.write('<input disabled type="text" name="price" size="8"
value=""></td>');
document.write('<td width="15%"><p align="right">');
document.write('<input disabled type="text" name="itemTotal" size="8"
value=""></td>');
document.write('</tr>');
document.write('</form>');
}
//
function printHiddenRow() {
document.write('<form>');
document.write('<input disabled type="hidden" name="itemDesc" size="35"
value="">');
document.write('<input type="hidden" name="itemQty" size="4" value=""
language="javascript" onChange="updateTable();">');
document.write('<input disabled type="hidden" name="price" size="8"
value="">');
document.write('<input disabled type="hidden" name="itemTotal" size="8"
value="">');
document.write('</form>');
}
//
function printSubtotal() {
document.write('</table>');
document.write('<form>');
document.write('<table border="1" cellpadding="2" width="100%"
bgcolor="beige">');
document.write('<tr>');
document.write('<td width="90%"><p align="right">Subtotal: </td>');
document.write('<td width="10%"><p align="right">');
document.write('<input disabled type="text" name="subTotal" size="10"
value="0"></td>');
document.write('</tr>');
document.write('<tr><td width="90%">');
document.write('<p><b>Shipping and Handling:</b> Shipping is currently
available in U.S. by UPS.</td>');
document.write('<td width="10%"><p align="right" >');
document.write('<input disabled type="text" name="shipping" size="10"
value="0"></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td width="90%"><p align="right">Total: </td>');
document.write('<td width="10%"><p align="right">');
document.write('<input disabled type="text" name="subTotal2" size="10"
value="0"></td>');
document.write('</tr>');
document.write('</table>');
document.write('</form>');
}
//
function calcTable() {
var subTotal=0;
var ship=0;
var subTotal2=0;
for (var i=0 ; i<number ; i++) {
prodTotals[i] = qty[i]*prices[i];
subTotal += prodTotals[i];
ship += qty[i]*shipping[i];
}
ship *= 1;
ship += 0;
subTotal2 = subTotal + ship;
sub2 = subTotal2;
for (var i=0 ; i<number ; i++) {
myForm = document.forms[i];
myForm.itemDesc.value = desc[i];
myForm.itemQty.value = qty[i];
myForm.price.value = convertPrice(prices[i]);
myForm.itemTotal.value = convertPrice(prodTotals[i]);
}
myForm = document.forms[number];
myForm.subTotal.value = convertPrice(subTotal);
myForm.shipping.value = convertPrice(ship);
myForm.subTotal2.value = convertPrice(subTotal2);
if (document.title == "Order Form") {
updateTax();
}
}
//
function updateTable() {
for (var i=0 ; i<number ; i++) {
myForm = document.forms[i];
var ckNum = parseInt(myForm.itemQty.value);
if (ckNum==myForm.itemQty.value) {
qty[i] = myForm.itemQty.value;
}
}
setCookie(name, qty.join());
calcTable();
}
//
function emptyCart() {
deleteCookie(name);
for (var i=0 ; i<number ; i++) {
qty[i] = 0;
}
setCookie(name, qty.join());
calcTable();
}
//
function printTopBC() {
document.write('<body aLink="yellow" bgColor="white" link="blue"
text="#543151" vLink="red">');
document.write('<font face="Helvetica, Arial">');
document.write('<h1 align="center">Cart Contents</h1>');
document.write('<p>&nbsp;</p>');
document.write('<p align="center"><i>You may change quantities below or
continue shopping.</i></p>');
}
//
function printBottomBC() {
document.write('<p>&nbsp;</p>');
document.write('<p align="center"><a
href="order.htm">Proceed to Order Form</a></p>');
document.write('<p align="center"><a href="index.htm">Continue
Shopping</a></p>');
document.write('<p>&nbsp;</p>');
document.write('<form>');
document.write('<p align="center"><input type="button" value="Empty cart"
name="B1" language="javascript" onClick="emptyCart();"></p>');
document.write('</form>');
document.write('<p align="center">&nbsp;</p>');
document.write('</body>');
document.write('</html>');
}
//
function calcTax() {
tax = taxRate * sub2;
tax /= 10000;
var temp = Math.round(tax);
tax = temp;
total = sub2 + tax;
}
//
function printTotal() {
document.write('<form>');
document.write('<table border="1" cellpadding="2" width="100%"
bgcolor="beige">');
document.write('<tr>');
document.write('<td width="90%"><p align="right">');
document.write('Sales Tax (7.9% sales tax will be included only if shipped
to Washington)</td>');
document.write('<td width="10%"><p align="right">');
document.write('<input disabled type="text" name="tax" size="10"
value="0"></td>');
document.write('</tr>');
document.write('<tr>');
document.write('<td width="90%"><p align="right">');
document.write('Total: </td>');
document.write('<td width="10%"><p align="right">');
document.write('<input disabled type="text" name="total" size="10"
value="0"></td>');
document.write('</tr>');
document.write('</table>');
document.write('</form>');
}
//
function updateTax() {
calcTax();
prepSubmit();
}
//
function prepSubmit() {
var description = "Hot New Stuff";
var itemDescription = "";
var itemNum = 1;
var j = 0;
myForm = document.forms[(number+1)];
myForm.tax.value = convertPrice(tax);
myForm.total.value = convertPrice(total);
myForm = document.forms[(number+2)];
myForm.x_Amount.value = convertPrice(total);
for (var i=0 ; i < number ; i++) {
if (qty[i] > 0) {
itemDescription = qty[i] + " " + desc[i] + " at " +
convertPrice(prices[i]) + " each";
if (j < number)
myForm.elements[j].value = itemDescription;
j++;
}
}
myForm.x_Description.value = description;
}
//
function printOrder() {
document.write('<body aLink="yellow" bgColor="white" link="blue"
text="#543151" vLink="red">');
document.write('<font face="Helvetica, Arial">');
document.write('<p align="center">');
document.write('<h1 align="center">Order Form</h1>');
document.write('<p>&nbsp;</p>');
}

Is it not possible to embed this call in this tag? Any help is greatly
appreciated. Thanks!

Philip M
04-17-2003, 06:52 AM
Your form is called : name="itemDesc"

Javascript is cAsEsEnsItIvE so itemdesc is not the same name as
itemDesc.

eZar
04-17-2003, 07:40 AM
Philip,

I don't see where the form is named "itemdesc". Which line are you referring to?

wox3-iO
04-17-2003, 11:04 AM
He ofcorse means this line:

Frontpage 2002. When I preview the script in IE6, I get an error on line 129 (in the Order.js) stating that the "myForm.itemdesc" is null or not an object

It's the 3rd line of your post.

Philip M
04-17-2003, 06:50 PM
Slip of the keyboard.

The form ELEMENT is apparantly called itemdesc but is referenced as itemDesc in your script line 129.

eZar
04-18-2003, 02:58 AM
My mistake, the error reads "itemDesc" not "itemdesc"...

I realize that JS is casesensitive, but this doesn't seem to be the case either...this problem is driving me up the wall...GRRRRR

Anymore suggestions?

Roy Sinclair
04-18-2003, 03:09 PM
Try bringing your page up in a browser other than IE. Try the Mozilla browser or it's commercial packed cousin Netscape 6 or 7 and use the Javascript Console it provides which will show you the exact line of your code where the problem exists instead of giving you a line number which you may have trouble finding like IE does.