Forums
This topic is locked
I hope I am asking in the correct forum?
Posted 19 Apr 2002 02:36:57
1
has voted
19 Apr 2002 02:36:57 hozae fire posted:
Newbie here....I am having a small problem I want a form that can individual add items across and then give a grand total on the bottom...a buddy helped me with this but I cant figure out the last part...any help would be appreciated.function compute(form) {
form.t1.value = (form.q1.value * form.p1.value);
form.t2.value = (form.q2.value * form.p2.value);
form.t3.value = (form.q3.value * form.p3.value);
form.grandtotal.value = (form.t3.value + form.t2.value);
}
function ClearForm(form) {
form.q1.value = "";
form.q2.value = "";
form.q3.value = "";
form.t1.value = "";
form.t2.value = "";
form.t3.value = "";
form.grandtotal.value = "";
}
My form is adding across, but my total is not showing the total it is show "111" instead of "3"...thanks , I hope I make sense if anyone has a tutorial on this language that would be helpful...thanks
Replies
Replied 19 Apr 2002 17:16:46
19 Apr 2002 17:16:46 hozae fire replied:
figured it out
form.grandtotal.value = (eval(form.t1.value) + eval(form.t2.value) + eval(form.t3.value)+ eval(form.t4.value);
can anyone tell me how to mask form.grandtotal.value , right now I get 1.2345 I would like to get 1.23....sorry for my ignorance , any help would be appreciated..
thanx
hoz
form.grandtotal.value = (eval(form.t1.value) + eval(form.t2.value) + eval(form.t3.value)+ eval(form.t4.value);
can anyone tell me how to mask form.grandtotal.value , right now I get 1.2345 I would like to get 1.23....sorry for my ignorance , any help would be appreciated..
thanx
hoz
Replied 19 Apr 2002 17:51:10
19 Apr 2002 17:51:10 aegis kleais replied:
Actaully, what's happening is called "Concatenation" Many times, the script langugage will see val + val (even if both values are numeric) as strings. Thus, "web" + "site" would = "website", however when values are "3" + "2", you'd expect 5, but got 32.
A quick way around this as well is to force it during expression as a number by subtracting 0. Thus:
(5-0) + (3-0) = 8 (and not 53)
A quick way around this as well is to force it during expression as a number by subtracting 0. Thus:
(5-0) + (3-0) = 8 (and not 53)
Replied 19 Apr 2002 18:12:23
19 Apr 2002 18:12:23 hozae fire replied:
Thanks I was able to get around that....my question is how do can I get $23.39 instead of $23.39999999...THanks for any help
Replied 19 Apr 2002 18:34:53
19 Apr 2002 18:34:53 aegis kleais replied:
<SCRIPT LANGUAGE="JavaScript"><!--
function cent(amount) {
// returns the amount in the .99 format
amount -= 0;
amount = (Math.round(amount*100))/100;
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
alert(isNaN(cent('a')));
alert(cent('001'));
alert(cent('1.7'));
alert(cent('1.444'));
//--></script>
function cent(amount) {
// returns the amount in the .99 format
amount -= 0;
amount = (Math.round(amount*100))/100;
return (amount == Math.floor(amount)) ? amount + '.00' : ( (amount*10 == Math.floor(amount*10)) ? amount + '0' : amount);
}
alert(isNaN(cent('a')));
alert(cent('001'));
alert(cent('1.7'));
alert(cent('1.444'));
//--></script>
Replied 22 Apr 2002 03:33:54
22 Apr 2002 03:33:54 hozae fire replied:
Sorry I am such an idiot...still cant get 34.59.... I keep getting 34.5999999900001
Thanks a bunch, for any help
hoz
<!--- hide from old browsers --- >
function compute(form) {
form.t1.value = (form.q1.value * form.p1.value);
form.t2.value = (form.q2.value * form.p2.value);
form.t3.value = (form.q3.value * form.p3.value);
form.t4.value = (form.q4.value * form.p4.value);
form.t5.value = (form.q5.value * form.p5.value);
form.t6.value = (form.q6.value * form.p6.value);
form.t7.value = (form.q7.value * form.p7.value);
form.t8.value = (form.q8.value * form.p8.value);
form.t9.value = (form.q9.value * form.p9.value);
form.t10.value = (form.q10.value * form.p10.value);
form.t11.value = (form.q11.value * form.p11.value);
form.t12.value = (form.q12.value * form.p12.value);
form.t13.value = (form.q13.value * form.p13.value);
form.t14.value = (form.q14.value * form.p14.value);
form.t15.value = (form.q15.value * form.p15.value);
form.t16.value = (form.q16.value * form.p16.value);
form.t17.value = (form.q17.value * form.p17.value);
form.t18.value = (form.q18.value * form.p18.value);
form.subtotal.value = (eval(form.t1.value) + eval(form.t2.value) + eval(form.t3.value)+ eval(form.t4.value)+ eval(form.t5.value)+ eval(form.t6.value)+ eval(form.t7.value)+ eval(form.t8.value)+ eval(form.t9.value)+ eval(form.t10.value)+ eval(form.t11.value)+ eval(form.t12.value)+ eval(form.t13.value)+ eval(form.t14.value)+ eval(form.t15.value)+ eval(form.t16.value)+ eval(form.t17.value)+ eval(form.t18.value));
form.grandtotal.value = (eval(form.t1.value) + eval(form.t2.value) + eval(form.t3.value)+ eval(form.t4.value)+ eval(form.t5.value)+ eval(form.t6.value)+ eval(form.t7.value)+ eval(form.t8.value)+ eval(form.t9.value)+ eval(form.t10.value)+ eval(form.t11.value)+ eval(form.t12.value)+ eval(form.t13.value)+ eval(form.t14.value)+ eval(form.t15.value)+ eval(form.t16.value)+ eval(form.t17.value)+ eval(form.t18.value));
}
function cent(form) {
grandtotal -= 0;
grandtotal = (Math.round(form.grandtotal.value*100))/100;
return (form.grandtotal.value == Math.floor(form.grandtotal.value)) ? form.grandtotal.value + '.00' : ( (form.grandtotal.value*10 == Math.floor(form.grandtotal.value*10)) ? form.grandtotal.value + '0' : form.grandtotal.value);
}
function ClearForm(form) {
form.q1.value = "";
form.q2.value = "";
form.q3.value = "";
form.q4.value = "";
form.q5.value = "";
form.q6.value = "";
form.q7.value = "";
form.q8.value = "";
form.q9.value = "";
form.q10.value = "";
form.q11.value = "";
form.q12.value = "";
form.q13.value = "";
form.q14.value = "";
form.q15.value = "";
form.q16.value = "";
form.q17.value = "";
form.q18.value = "";
form.t1.value = "$0.00";
form.t2.value = "$0.00";
form.t3.value = "$0.00";
form.t4.value = "$0.00";
form.t5.value = "$0.00";
form.t6.value = "$0.00";
form.t7.value = "$0.00";
form.t8.value = "$0.00";
form.t9.value = "$0.00";
form.t10.value = "$0.00";
form.t11.value = "$0.00";
form.t12.value = "$0.00";
form.t13.value = "$0.00";
form.t14.value = "$0.00";
form.t15.value = "$0.00";
form.t16.value = "$0.00";
form.t17.value = "$0.00";
form.t18.value = "$0.00";
form.subtotal.value = "$0.00";
form.grandtotal.value = "$0.00";
}
<!-- done hiding from old browsers -->
Thanks a bunch, for any help
hoz
<!--- hide from old browsers --- >
function compute(form) {
form.t1.value = (form.q1.value * form.p1.value);
form.t2.value = (form.q2.value * form.p2.value);
form.t3.value = (form.q3.value * form.p3.value);
form.t4.value = (form.q4.value * form.p4.value);
form.t5.value = (form.q5.value * form.p5.value);
form.t6.value = (form.q6.value * form.p6.value);
form.t7.value = (form.q7.value * form.p7.value);
form.t8.value = (form.q8.value * form.p8.value);
form.t9.value = (form.q9.value * form.p9.value);
form.t10.value = (form.q10.value * form.p10.value);
form.t11.value = (form.q11.value * form.p11.value);
form.t12.value = (form.q12.value * form.p12.value);
form.t13.value = (form.q13.value * form.p13.value);
form.t14.value = (form.q14.value * form.p14.value);
form.t15.value = (form.q15.value * form.p15.value);
form.t16.value = (form.q16.value * form.p16.value);
form.t17.value = (form.q17.value * form.p17.value);
form.t18.value = (form.q18.value * form.p18.value);
form.subtotal.value = (eval(form.t1.value) + eval(form.t2.value) + eval(form.t3.value)+ eval(form.t4.value)+ eval(form.t5.value)+ eval(form.t6.value)+ eval(form.t7.value)+ eval(form.t8.value)+ eval(form.t9.value)+ eval(form.t10.value)+ eval(form.t11.value)+ eval(form.t12.value)+ eval(form.t13.value)+ eval(form.t14.value)+ eval(form.t15.value)+ eval(form.t16.value)+ eval(form.t17.value)+ eval(form.t18.value));
form.grandtotal.value = (eval(form.t1.value) + eval(form.t2.value) + eval(form.t3.value)+ eval(form.t4.value)+ eval(form.t5.value)+ eval(form.t6.value)+ eval(form.t7.value)+ eval(form.t8.value)+ eval(form.t9.value)+ eval(form.t10.value)+ eval(form.t11.value)+ eval(form.t12.value)+ eval(form.t13.value)+ eval(form.t14.value)+ eval(form.t15.value)+ eval(form.t16.value)+ eval(form.t17.value)+ eval(form.t18.value));
}
function cent(form) {
grandtotal -= 0;
grandtotal = (Math.round(form.grandtotal.value*100))/100;
return (form.grandtotal.value == Math.floor(form.grandtotal.value)) ? form.grandtotal.value + '.00' : ( (form.grandtotal.value*10 == Math.floor(form.grandtotal.value*10)) ? form.grandtotal.value + '0' : form.grandtotal.value);
}
function ClearForm(form) {
form.q1.value = "";
form.q2.value = "";
form.q3.value = "";
form.q4.value = "";
form.q5.value = "";
form.q6.value = "";
form.q7.value = "";
form.q8.value = "";
form.q9.value = "";
form.q10.value = "";
form.q11.value = "";
form.q12.value = "";
form.q13.value = "";
form.q14.value = "";
form.q15.value = "";
form.q16.value = "";
form.q17.value = "";
form.q18.value = "";
form.t1.value = "$0.00";
form.t2.value = "$0.00";
form.t3.value = "$0.00";
form.t4.value = "$0.00";
form.t5.value = "$0.00";
form.t6.value = "$0.00";
form.t7.value = "$0.00";
form.t8.value = "$0.00";
form.t9.value = "$0.00";
form.t10.value = "$0.00";
form.t11.value = "$0.00";
form.t12.value = "$0.00";
form.t13.value = "$0.00";
form.t14.value = "$0.00";
form.t15.value = "$0.00";
form.t16.value = "$0.00";
form.t17.value = "$0.00";
form.t18.value = "$0.00";
form.subtotal.value = "$0.00";
form.grandtotal.value = "$0.00";
}
<!-- done hiding from old browsers -->
Replied 25 Apr 2002 05:08:34
25 Apr 2002 05:08:34 hozae fire replied:
Math.round was the trick ...thanks a lot...
hoz
hoz