[thelist] function calculate()

Anthony Baratta Anthony at Baratta.com
Mon Oct 23 12:15:45 CDT 2000


At 07:44 AM 10/23/2000, you wrote:

>Instead of getting a grand total in the BdCostTotal form field, I get an
>appended answer.  Let's say I put the value
>1 in BdCost Advertising field and 2 in the BdCost Labor field.  Instead of
>getting 3, I get 12.  I tried adding "eval"
>before each (document.Front...) and received a NaN response.


Here's what I do...

function reCalcOrderForm() {
     document.FormOOS.EDUSubtotal.value = 0
     if (document.FormOOS.FoodPicturesQty.value != "") {
         document.FormOOS.FoodPicturesSubtotal.value = 
parseInt(document.FormOOS.FoodPicturesQty.value) * 15;
         document.FormOOS.EDUSubtotal.value = 
parseFloat(document.FormOOS.EDUSubtotal.value) + 
parseFloat(document.FormOOS.FoodPicturesSubtotal.value);
     }
     if (document.FormOOS.EYOQty.value != "") {
         document.FormOOS.EYOSubtotal.value = 
parseInt(document.FormOOS.EYOQty.value) * 32.50;
         document.FormOOS.EDUSubtotal.value = 
parseFloat(document.FormOOS.EDUSubtotal.value) + 
parseFloat(document.FormOOS.EYOSubtotal.value);
     }
     if (document.FormOOS.EYOTeacherQty.value != "") {
         document.FormOOS.EYOTeacherSubtotal.value = 
parseInt(document.FormOOS.EYOTeacherQty.value) * 13.25;
         document.FormOOS.EDUSubtotal.value = 
parseFloat(document.FormOOS.EDUSubtotal.value) + 
parseFloat(document.FormOOS.EYOTeacherSubtotal.value);
     }
     if (document.FormOOS.EYOStudentQty.value != "") {
         document.FormOOS.EYOStudentSubtotal.value = 
parseInt(document.FormOOS.EYOStudentQty.value) * 20;
         document.FormOOS.EDUSubtotal.value = 
parseFloat(document.FormOOS.EDUSubtotal.value) + 
parseFloat(document.FormOOS.EYOStudentSubtotal.value);
     }
}

This basically multiplies the Quantity with a hard coded price, if the 
Quantity is not blank. (There should probably be a NAN evaluation after 
identifying that the field is not blank.) I re-do all this on the server 
side anyway with stricter format checks (and especially ignoring the totals 
generated by the Javascript - I only use the Quantities and re-capture the 
prices from my service side price list), so the JavaScipt is just icing on 
the cake.


----
Anthony Baratta
President
Keyboard Jockeys





More information about the thelist mailing list