Sonia
07-28-2003, 08:22 AM
The following code is found in a shopping cart. It's function is to display the products chosen by the user in a table.
Can anyone explain me that code.Plzzz
function showItems() {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln('<TABLE BORDER>');
document.writeln('<TR><TD><b>Item</b></TD><TD><b>Quantity</b></TD><TD><b>Cost Each</b></TD><td><b>Total Cost</b></TR>');
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
totprice = totprice + itemtotal;
itemlist=itemlist+1;
document.writeln("<form name='f1' action = 'mailto:Gounshali@yahoo.com' enctype = 'text/plain' method = 'post' ><tr><td><input name = 'Item' value = ' " + theitem + " ' ></td><td align=right>" + thequantity + "</td><td align=right> " + theprice + "</td><td align=right>" + alterError(itemtotal) + "</td></tr>");
} else if (fulllist.substring(i,i+1) == ',') {
theitem = fulllist.substring(itemstart, i);
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == '#') {
theprice = fulllist.substring(itemstart, i);
itemstart = i+1;
}
}
document.writeln('<tr><td colspan=3><b>Total</b></td><td align=right>'+ alterError(totprice)+'</td><td></td></tr>');
document.writeln('</TABLE>');
}
Can anyone explain me that code.Plzzz
function showItems() {
index = document.cookie.indexOf("TheBasket");
countbegin = (document.cookie.indexOf("=", index) + 1);
countend = document.cookie.indexOf(";", index);
if (countend == -1) {
countend = document.cookie.length;
}
fulllist = document.cookie.substring(countbegin, countend);
totprice = 0;
document.writeln('<TABLE BORDER>');
document.writeln('<TR><TD><b>Item</b></TD><TD><b>Quantity</b></TD><TD><b>Cost Each</b></TD><td><b>Total Cost</b></TR>');
itemlist = 0;
for (var i = 0; i <= fulllist.length; i++) {
if (fulllist.substring(i,i+1) == '[') {
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == ']') {
itemend = i;
thequantity = fulllist.substring(itemstart, itemend);
itemtotal = 0;
itemtotal = (eval(theprice*thequantity));
temptotal = itemtotal * 100;
totprice = totprice + itemtotal;
itemlist=itemlist+1;
document.writeln("<form name='f1' action = 'mailto:Gounshali@yahoo.com' enctype = 'text/plain' method = 'post' ><tr><td><input name = 'Item' value = ' " + theitem + " ' ></td><td align=right>" + thequantity + "</td><td align=right> " + theprice + "</td><td align=right>" + alterError(itemtotal) + "</td></tr>");
} else if (fulllist.substring(i,i+1) == ',') {
theitem = fulllist.substring(itemstart, i);
itemstart = i+1;
} else if (fulllist.substring(i,i+1) == '#') {
theprice = fulllist.substring(itemstart, i);
itemstart = i+1;
}
}
document.writeln('<tr><td colspan=3><b>Total</b></td><td align=right>'+ alterError(totprice)+'</td><td></td></tr>');
document.writeln('</TABLE>');
}