Click to See Complete Forum and Search --> : Form calculate


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;

}

Khalid Ali
10-11-2003, 11:14 AM
please mention the errors you are getting, or post the link to the page where you have this implemented

tykst
10-11-2003, 11:21 AM
here's the attached form.. if it helps.
it's a htm file but I've changed the extension to .txt to post it here

Khalid Ali
10-11-2003, 11:39 AM
the first errors I seeare these. replace these 2 lines

document.frmOne.qty_total.value = grandQty;
document.frmOne.cost_total.value = grandQty*15;

with these 2 lines

document.frmOne.QTY_TOTAL.value = grandQty;
document.frmOne.COST_TOTAL.value = grandQty*15;

for submission.you will have to let me know the error you are getting.I can not guess what is the error in that respect.

tykst
10-12-2003, 03:33 AM
Unbelievable! All this while, it was juz an uppercap/lowercap issue?? >___< Those hours of sleep I've wasted trying to figure out! Thank you sooo much, you're my saviour!! After changing those two lines, everything's working fine. Thank you!! ^ ^

tykst
10-28-2003, 09:45 PM
:mad:
Give them something good and they will ask for more.

Now the follks I'm doing this form for wants the following conditions:

1) when the user clicks CALCULATE, fields that were empty remains empty instead of showing a "0"

2) onClick submit, fields that were not filled in will not appear in the sent information at all.

:( what do I do?

-- tykst --