|
-
November 12th, 2002, 11:21 AM
#1
pplease help me-with this part of code for a cart
here is the code for my cart. it is weird, i dont want "Decimal" quantity multiplying the price. how do change that so if someone inputs 1.5 as quantity it five sout an error. here is the code:
function MakeTen(expr,decimal){
var str="" + Math.round(eval(expr) * Math.pow(10,decimal))
while (str.length <= decimal){
str = "0" + str
}
var decpoint = str.length - decimal
return str.substring(0,decpoint) + "." + str.substring(decpoint,str.length);
}
function MakeTwo(expr){
return "$" + MakeTen(expr,2)
}
function cartMe() {
index = document.cookie.indexOf("MyCart");
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.write('<TABLE BORDER=1 CELLSPACING=2 CELLPADDING=2 BGCOLOR=adcfdc>');
document.write('<TR><TD><b>Qty</b></TD><TD><b>Product</b></TD><TD><FONT COLOR="#FFFFFF">.</FONT></TD><TD><b>Price</b></TD><td><b>Sub total</b></TD><TD><FONT COLOR="#FFFFFF">.</FONT></TD></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.write('<tr><td align=middle>'+thequantity+'</td><td align=left>'+theitem+'</td><td align=right>'+theoption+'</td><td align=right>$'+theprice+'</td><td align=right>'+top.menu.MakeTwo(itemtotal)+'</td><td><a href="javascript:removeItem('+itemlist+')">Remove</a></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;
}
else if (fulllist.substring(i,i+1) == '~') {
theoption = fulllist.substring(itemstart, i);
itemstart = i+1;
}
}
document.write('<tr><td align=right colspan=4><b>Total</b></td><td align=right>'+top.menu.MakeTwo(totprice)+'</td><TD><FONT COLOR="#FFFFFF">.</FONT></TD></tr>');
document.write('</TABLE>');
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|