[thelist] Form & Grand Total

Anthony Baratta Tony at IdeaSystems.com
Fri Oct 20 12:31:47 CDT 2000


At 10:01 AM 10/20/2000, you wrote:


>Does anyone have or know where I can l get a javascript that will add the 
>values
>a user enters into 12 separate input fields to ultimately come up with the 
>grand
>total
>of those values?  It is very possible that users will leave some or all input
>fields empty.

Here is a cut and paste example I slapped together for another site I did:

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.BHMQty.value != "") {
         document.FormOOS.BHMSubtotal.value = 
parseInt(document.FormOOS.BHMQty.value) * 35;
         document.FormOOS.EDUSubtotal.value = 
parseFloat(document.FormOOS.EDUSubtotal.value) + 
parseFloat(document.FormOOS.BHMSubtotal.value);
     }
     if (document.FormOOS.HCHMQty.value != "") {
         document.FormOOS.HCHMSubtotal.value = 
parseInt(document.FormOOS.HCHMQty.value) * 33;
         document.FormOOS.EDUSubtotal.value = 
parseFloat(document.FormOOS.EDUSubtotal.value) + 
parseFloat(document.FormOOS.HCHMSubtotal.value);
     }
     if (document.FormOOS.HCHMStudentQty.value != "") {
         document.FormOOS.HCHMStudentSubtotal.value = 
parseInt(document.FormOOS.HCHMStudentQty.value) * 12;
         document.FormOOS.EDUSubtotal.value = 
parseFloat(document.FormOOS.EDUSubtotal.value) + 
parseFloat(document.FormOOS.HCHMStudentSubtotal.value);
     }
     if (document.FormOOS.SUMCQty.value != "") {
         document.FormOOS.SUMCSubtotal.value = 
parseInt(document.FormOOS.SUMCQty.value) * 33;
         document.FormOOS.EDUSubtotal.value = 
parseFloat(document.FormOOS.EDUSubtotal.value) + 
parseFloat(document.FormOOS.SUMCSubtotal.value);
     }
     if (document.FormOOS.SUMCStudentQty.value != "") {
         document.FormOOS.SUMCStudentSubtotal.value = 
parseInt(document.FormOOS.SUMCStudentQty.value) * 12;
         document.FormOOS.EDUSubtotal.value = 
parseFloat(document.FormOOS.EDUSubtotal.value) + 
parseFloat(document.FormOOS.SUMCStudentSubtotal.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);
     }
}

Inside the input elements (both the Quantities and sub Totals) put this:

          onChange="reCalcOrderForm()"


----
Anthony Baratta
President
Keyboard Jockeys





More information about the thelist mailing list