I've got a form where I'm calculating the shipping costs of several items, and it's working so far except that the result needs to be rounded to 2 decimal points. Pardon my inexperience, this could be very badly written and if you want to give me a way to simplify, I'd appreciate that too! Basically I have T-shirts, sweatshirts & tote bags that ship at $4.25 for the first and $1.50 each additional, calendars at the same, cookbooks at the same, and notecards at the same. Yes the shipping cost is separate for each of the 4 categories, since they all come from different places. Thanks for any help!
function calcShipping() {
var shipping = 0
if ((document.orderForm.shirt_sm.value + document.orderForm.shirt_med.value +
document.orderForm.shirt_lg.value + document.orderForm.shirt_xl.value +
document.orderForm.shirt_2x.value + document.orderForm.shirt_3x.value +
document.orderForm.shirt_4x.value + document.orderForm.sweat_med.value +
document.orderForm.sweat_lg.value + document.orderForm.sweat_xl.value +
document.orderForm.sweat_2x.value + document.orderForm.totes.value) >0) {
shipItems = (4.25 + (( (document.orderForm.shirt_sm.value +
document.orderForm.shirt_med.value + document.orderForm.shirt_lg.value +
document.orderForm.shirt_xl.value + document.orderForm.shirt_2x.value +
document.orderForm.shirt_3x.value + document.orderForm.shirt_4x.value +
document.orderForm.sweat_med.value + document.orderForm.sweat_lg.value +
document.orderForm.sweat_xl.value + document.orderForm.sweat_2x.value +
document.orderForm.totes.value) - 1) * 1.5));
} else {
shipItems = "0";
}
if (document.orderForm.calendars.value >0) {
shipCals = (4.25 + (((document.orderForm.calendars.value) - 1) * 1.5));
} else {
shipCals = "0";
}
if ( document.orderForm.cookbooks.value >0) {
shipBooks = (4.25 + (((document.orderForm.cookbooks.value) - 1) * 1.5));
} else {
shipBooks = "0";
}
if (document.orderForm.notecards.value >0) {
shipCards = (4.25 + (((document.orderForm.notecards.value) - 1) * 1.5));
} else {
shipCards = "0";
}
document.orderForm.shipping.value = (shipItems + shipCals + shipBooks + shipCards)
}
function calcShipping() {
var shipping = 0
if ((document.orderForm.shirt_sm.value + document.orderForm.shirt_med.value +
document.orderForm.shirt_lg.value + document.orderForm.shirt_xl.value +
document.orderForm.shirt_2x.value + document.orderForm.shirt_3x.value +
document.orderForm.shirt_4x.value + document.orderForm.sweat_med.value +
document.orderForm.sweat_lg.value + document.orderForm.sweat_xl.value +
document.orderForm.sweat_2x.value + document.orderForm.totes.value) >0) {
shipItems = (4.25 + (( (document.orderForm.shirt_sm.value +
document.orderForm.shirt_med.value + document.orderForm.shirt_lg.value +
document.orderForm.shirt_xl.value + document.orderForm.shirt_2x.value +
document.orderForm.shirt_3x.value + document.orderForm.shirt_4x.value +
document.orderForm.sweat_med.value + document.orderForm.sweat_lg.value +
document.orderForm.sweat_xl.value + document.orderForm.sweat_2x.value +
document.orderForm.totes.value) - 1) * 1.5));
} else {
shipItems = "0";
}
if (document.orderForm.calendars.value >0) {
shipCals = (4.25 + (((document.orderForm.calendars.value) - 1) * 1.5));
} else {
shipCals = "0";
}
if ( document.orderForm.cookbooks.value >0) {
shipBooks = (4.25 + (((document.orderForm.cookbooks.value) - 1) * 1.5));
} else {
shipBooks = "0";
}
if (document.orderForm.notecards.value >0) {
shipCards = (4.25 + (((document.orderForm.notecards.value) - 1) * 1.5));
} else {
shipCards = "0";
}
document.orderForm.shipping.value = (shipItems + shipCals + shipBooks + shipCards)
}