tykst
10-11-2003, 11:10 AM
hi guys, I'm trying to get my form to calculate sub totals, add the subs and multiply the grand total by $15. And onsubmit, sends the calculation + some other user information... I got this working calculation code from somewhere but when put together with other fields, it malfunctions!! I need to do this but I'm a web designer and know nuts about anything beyond HTML... it'll probably take a programmer to solve it within 5 minutes but i've been at it for days... please help me look at he codes beneath?
<!-- --------- the script ---------->
function initZero(obj){
if (obj.value=="") {
obj.value="0";
}
}
function calculate(){
var frm = document.frmOne;
var len = frm.length;
for(x=0;x<len;x++){
initZero(frm[x]);
}
A1 = document.frmOne.RED_XS.value;
B1 = document.frmOne.RED_S.value;
C1 = document.frmOne.RED_M.value;
D1 = document.frmOne.RED_L.value;
E1 = document.frmOne.RED_XL.value;
F1 = document.frmOne.RED_XXL.value;
sub1 = parseInt(A1) + parseInt(B1) + parseInt(C1) + parseInt(D1) + parseInt(E1) + parseInt(F1);
document.frmOne.RED_TOTAL.value = sub1;
A2 = document.frmOne.WHITE_XS.value;
B2 = document.frmOne.WHITE_S.value;
C2 = document.frmOne.WHITE_M.value;
D2 = document.frmOne.WHITE_L.value;
E2 = document.frmOne.WHITE_XL.value;
F2 = document.frmOne.WHITE_XXL.value;
sub2 = parseInt(A2) + parseInt(B2) + parseInt(C2) + parseInt(D2) + parseInt(E2) + parseInt(F2);
document.frmOne.WHITE_TOTAL.value = sub2;
A3 = document.frmOne.BLACK_XS.value;
B3 = document.frmOne.BLACK_S.value;
C3 = document.frmOne.BLACK_M.value;
D3 = document.frmOne.BLACK_L.value;
E3 = document.frmOne.BLACK_XL.value;
F3 = document.frmOne.BLACK_XXL.value;
sub3 = parseInt(A3) + parseInt(B3) + parseInt(C3) + parseInt(D3) + parseInt(E3) + parseInt(F3);
document.frmOne.BLACK_TOTAL.value = sub3;
A4 = document.frmOne.BLUE_XS.value;
B4 = document.frmOne.BLUE_S.value;
C4 = document.frmOne.BLUE_M.value;
D4 = document.frmOne.BLUE_L.value;
E4 = document.frmOne.BLUE_XL.value;
F4 = document.frmOne.BLUE_XXL.value;
sub4 = parseInt(A4) + parseInt(B4) + parseInt(C4) + parseInt(D4) + parseInt(E4) + parseInt(F4);
document.frmOne.BLUE_TOTAL.value = sub4;
// initalize the total
grandQty = sub1 + sub2 + sub3 + sub4
document.frmOne.qty_total.value = grandQty;
document.frmOne.cost_total.value = grandQty*15;
}
<!-- --------- the script ---------->
function initZero(obj){
if (obj.value=="") {
obj.value="0";
}
}
function calculate(){
var frm = document.frmOne;
var len = frm.length;
for(x=0;x<len;x++){
initZero(frm[x]);
}
A1 = document.frmOne.RED_XS.value;
B1 = document.frmOne.RED_S.value;
C1 = document.frmOne.RED_M.value;
D1 = document.frmOne.RED_L.value;
E1 = document.frmOne.RED_XL.value;
F1 = document.frmOne.RED_XXL.value;
sub1 = parseInt(A1) + parseInt(B1) + parseInt(C1) + parseInt(D1) + parseInt(E1) + parseInt(F1);
document.frmOne.RED_TOTAL.value = sub1;
A2 = document.frmOne.WHITE_XS.value;
B2 = document.frmOne.WHITE_S.value;
C2 = document.frmOne.WHITE_M.value;
D2 = document.frmOne.WHITE_L.value;
E2 = document.frmOne.WHITE_XL.value;
F2 = document.frmOne.WHITE_XXL.value;
sub2 = parseInt(A2) + parseInt(B2) + parseInt(C2) + parseInt(D2) + parseInt(E2) + parseInt(F2);
document.frmOne.WHITE_TOTAL.value = sub2;
A3 = document.frmOne.BLACK_XS.value;
B3 = document.frmOne.BLACK_S.value;
C3 = document.frmOne.BLACK_M.value;
D3 = document.frmOne.BLACK_L.value;
E3 = document.frmOne.BLACK_XL.value;
F3 = document.frmOne.BLACK_XXL.value;
sub3 = parseInt(A3) + parseInt(B3) + parseInt(C3) + parseInt(D3) + parseInt(E3) + parseInt(F3);
document.frmOne.BLACK_TOTAL.value = sub3;
A4 = document.frmOne.BLUE_XS.value;
B4 = document.frmOne.BLUE_S.value;
C4 = document.frmOne.BLUE_M.value;
D4 = document.frmOne.BLUE_L.value;
E4 = document.frmOne.BLUE_XL.value;
F4 = document.frmOne.BLUE_XXL.value;
sub4 = parseInt(A4) + parseInt(B4) + parseInt(C4) + parseInt(D4) + parseInt(E4) + parseInt(F4);
document.frmOne.BLUE_TOTAL.value = sub4;
// initalize the total
grandQty = sub1 + sub2 + sub3 + sub4
document.frmOne.qty_total.value = grandQty;
document.frmOne.cost_total.value = grandQty*15;
}