PDA

View Full Version : Lost totals with new Variables


vertronics
07-12-2002, 05:26 PM
Hi, I am editing a Javascript which calcutates several totals. This worked fine until I add new variables for child and adult individual skiing days. Can someone tell me what's wrong with the new script?

This script works:
<script language="javascript">
function calculateTotals() {
var form = document.orderForm;
// NOTE: child totals

form.child6Total.value = form.child6Quantity.value * form.child6RegularRate.value;
form.child5Total.value = form.child5Quantity.value * form.child5RegularRate.value;
form.child4Total.value = form.child4Quantity.value * form.child4RegularRate.value;

// NOTE: adult totals

form.adult6Total.value = form.adult6Quantity.value * form.adult6RegularRate.value;
form.adult5Total.value = form.adult5Quantity.value * form.adult5RegularRate.value;
form.adult4Total.value = form.adult4Quantity.value * form.adult4RegularRate.value;

// NOTE: senior totals
form.seniorTotal.value = form.seniorQuantity.value * form.seniorRegularRate.value;
// NOTE: sub-totals for child
// form.childGrandSkiingDays.value =
// (form.child6Quantity.value * 6)
// + (form.child5Quantity.value * 5)
// + (form.child4Quantity.value * 4);
form.childGrandQuantity.value =
(form.child6Quantity.value * 1)
+ (form.child5Quantity.value * 1)
+ (form.child4Quantity.value * 1);

form.childGrandTotal.value = (form.child6Total.value * 1)
+ (form.child5Total.value * 1)
+ (form.child4Total.value * 1);


// NOTE: sub-totals for adult
// form.adultGrandSkiingDays.value = (form.adult6Quantity.value * 6)
// + (form.adult5Quantity.value * 5)
// + (form.adult4Quantity.value * 4);

form.adultGrandQuantity.value = (form.adult6Quantity.value * 1)
+ (form.adult5Quantity.value * 1)
+ (form.adult4Quantity.value * 1);

form.adultGrandTotal.value = (form.adult6Total.value * 1)
+ (form.adult5Total.value * 1)
+ (form.adult4Total.value * 1);


// NOTE: grand total of days
// form.grandSkiingDays.value = (form.infantNumberOfDays.value * form.infantQuantity.value)
// + (form.childGrandSkiingDays.value * 1)
// + (form.adultGrandSkiingDays.value * 1);
// NOTE: grand total of tickets
form.grandQuantity.value = (form.childGrandQuantity.value * 1)
+ (form.adultGrandQuantity.value * 1)
+ (form.seniorQuantity.value * 1);
// NOTE: grand $ total
form.grandTotal.value = (form.childGrandTotal.value * 1)
+ (form.adultGrandTotal.value * 1)
+ (form.seniorTotal.value * 1);
}
</script>


:confused:

This is the new script which causes my grandTotals to fail (
the totals don't show up)


<script language="javascript">
function calculateTotals() {
var form = document.orderForm;
// NOTE: child totals

form.child6Total.value = form.child6Quantity.value * form.child6RegularRate.value;
form.child5Total.value = form.child5Quantity.value * form.child5RegularRate.value;
form.child4Total.value = form.child4Quantity.value * form.child4RegularRate.value;

// NOTE: adult totals

form.adult6Total.value = form.adult6Quantity.value * form.adult6RegularRate.value;
form.adult5Total.value = form.adult5Quantity.value * form.adult5RegularRate.value;
form.adult4Total.value = form.adult4Quantity.value * form.adult4RegularRate.value;

// NOTE: senior totals
form.seniorTotal.value = form.seniorQuantity.value * form.seniorRegularRate.value;
// NOTE: sub-totals for child
// form.childGrandSkiingDays.value =
// (form.child6Quantity.value * 6)
// + (form.child5Quantity.value * 5)
// + (form.child4Quantity.value * 4);


// NOTE: totals for child individual skiing days
// form.childSkiingDays6.value = (form.child6Quantity.value * 1);
// form.childSkiingDays5.value = (form.child5Quantity.value * 1);
//form.childSkiingDays4.value = (form.child4.Quantity.value * 1);


form.childGrandQuantity.value =
(form.child6Quantity.value * 1)
+ (form.child5Quantity.value * 1)
+ (form.child4Quantity.value * 1);

form.childGrandTotal.value = (form.child6Total.value * 1)
+ (form.child5Total.value * 1)
+ (form.child4Total.value * 1);


// NOTE: sub-totals for adult
// form.adultGrandSkiingDays.value = (form.adult6Quantity.value * 6)
// + (form.adult5Quantity.value * 5)
// + (form.adult4Quantity.value * 4);

// NOTE: totals for adult individual skiing days
// form.adultSkiingDays6.value = (form.adult6Quantity.value * 1);
// form.adultSkiingDays5.value = (form.adult5Quantity.value * 1);
//form.adultSkiingDays4.value = (form.adult4Quantity.value * 1);

form.adultGrandQuantity.value = (form.adult6Quantity.value * 1)
+ (form.adult5Quantity.value * 1)
+ (form.adult4Quantity.value * 1);

form.adultGrandTotal.value = (form.adult6Total.value * 1)
+ (form.adult5Total.value * 1)
+ (form.adult4Total.value * 1);


// NOTE: grand total of days
// form.grandSkiingDays.value = (form.infantNumberOfDays.value * form.infantQuantity.value)
// + (form.childGrandSkiingDays.value * 1)
// + (form.adultGrandSkiingDays.value * 1);
// NOTE: grand total of tickets
form.grandQuantity.value = (form.childGrandQuantity.value * 1)
+ (form.adultGrandQuantity.value * 1)
+ (form.seniorQuantity.value * 1);
// NOTE: grand $ total
form.grandTotal.value = (form.childGrandTotal.value * 1)
+ (form.adultGrandTotal.value * 1)
+ (form.seniorTotal.value * 1);
}
</script>


Thanks in advance!
~cherylw

vertronics
07-12-2002, 06:10 PM
Hi,

I made a mistake during the inital post:
Here is the code that breaks my totals. This happens once I added indiviual skiing days to the script ( child /adult). :confused:

<script language="javascript">
function calculateTotals() {
var form = document.orderForm;
// NOTE: child totals

form.child6Total.value = form.child6Quantity.value * form.child6RegularRate.value;
form.child5Total.value = form.child5Quantity.value * form.child5RegularRate.value;
form.child4Total.value = form.child4Quantity.value * form.child4RegularRate.value;

// NOTE: adult totals

form.adult6Total.value = form.adult6Quantity.value * form.adult6RegularRate.value;
form.adult5Total.value = form.adult5Quantity.value * form.adult5RegularRate.value;
form.adult4Total.value = form.adult4Quantity.value * form.adult4RegularRate.value;

// NOTE: senior totals
form.seniorTotal.value = form.seniorQuantity.value * form.seniorRegularRate.value;
// NOTE: sub-totals for child
// form.childGrandSkiingDays.value =
// (form.child6Quantity.value * 6)
// + (form.child5Quantity.value * 5)
// + (form.child4Quantity.value * 4);


// NOTE: totals for child individual skiing days
form.childSkiingDays6.value = (form.child6Quantity.value * 1);
form.childSkiingDays5.value = (form.child5Quantity.value * 1);
form.childSkiingDays4.value = (form.child4.Quantity.value * 1);


form.childGrandQuantity.value =
(form.child6Quantity.value * 1)
+ (form.child5Quantity.value * 1)
+ (form.child4Quantity.value * 1);

form.childGrandTotal.value = (form.child6Total.value * 1)
+ (form.child5Total.value * 1)
+ (form.child4Total.value * 1);


// NOTE: sub-totals for adult
// form.adultGrandSkiingDays.value = (form.adult6Quantity.value * 6)
// + (form.adult5Quantity.value * 5)
// + (form.adult4Quantity.value * 4);

// NOTE: totals for adult individual skiing days
form.adultSkiingDays6.value = (form.adult6Quantity.value * 1);
form.adultSkiingDays5.value = (form.adult5Quantity.value * 1);
form.adultSkiingDays4.value = (form.adult4Quantity.value * 1);

form.adultGrandQuantity.value = (form.adult6Quantity.value * 1)
+ (form.adult5Quantity.value * 1)
+ (form.adult4Quantity.value * 1);

form.adultGrandTotal.value = (form.adult6Total.value * 1)
+ (form.adult5Total.value * 1)
+ (form.adult4Total.value * 1);


// NOTE: grand total of days
// form.grandSkiingDays.value = (form.infantNumberOfDays.value * form.infantQuantity.value)
// + (form.childGrandSkiingDays.value * 1)
// + (form.adultGrandSkiingDays.value * 1);
// NOTE: grand total of tickets
form.grandQuantity.value = (form.childGrandQuantity.value * 1)
+ (form.adultGrandQuantity.value * 1)
+ (form.seniorQuantity.value * 1);
// NOTE: grand $ total
form.grandTotal.value = (form.childGrandTotal.value * 1)
+ (form.adultGrandTotal.value * 1)
+ (form.seniorTotal.value * 1);
}
</script>


This code, gives me my totals and grandtotals, I commented out the indivual skiing days code:


script language="javascript">
function calculateTotals() {
var form = document.orderForm;
// NOTE: child totals

form.child6Total.value = form.child6Quantity.value * form.child6RegularRate.value;
form.child5Total.value = form.child5Quantity.value * form.child5RegularRate.value;
form.child4Total.value = form.child4Quantity.value * form.child4RegularRate.value;

// NOTE: adult totals

form.adult6Total.value = form.adult6Quantity.value * form.adult6RegularRate.value;
form.adult5Total.value = form.adult5Quantity.value * form.adult5RegularRate.value;
form.adult4Total.value = form.adult4Quantity.value * form.adult4RegularRate.value;

// NOTE: senior totals
form.seniorTotal.value = form.seniorQuantity.value * form.seniorRegularRate.value;
// NOTE: sub-totals for child
// form.childGrandSkiingDays.value =
// (form.child6Quantity.value * 6)
// + (form.child5Quantity.value * 5)
// + (form.child4Quantity.value * 4);


// NOTE: totals for child individual skiing days
// form.childSkiingDays6.value = (form.child6Quantity.value * 1);
// form.childSkiingDays5.value = (form.child5Quantity.value * 1);
//form.childSkiingDays4.value = (form.child4.Quantity.value * 1);


form.childGrandQuantity.value =
(form.child6Quantity.value * 1)
+ (form.child5Quantity.value * 1)
+ (form.child4Quantity.value * 1);

form.childGrandTotal.value = (form.child6Total.value * 1)
+ (form.child5Total.value * 1)
+ (form.child4Total.value * 1);


// NOTE: sub-totals for adult
// form.adultGrandSkiingDays.value = (form.adult6Quantity.value * 6)
// + (form.adult5Quantity.value * 5)
// + (form.adult4Quantity.value * 4);

// NOTE: totals for adult individual skiing days
// form.adultSkiingDays6.value = (form.adult6Quantity.value * 1);
// form.adultSkiingDays5.value = (form.adult5Quantity.value * 1);
//form.adultSkiingDays4.value = (form.adult4Quantity.value * 1);

form.adultGrandQuantity.value = (form.adult6Quantity.value * 1)
+ (form.adult5Quantity.value * 1)
+ (form.adult4Quantity.value * 1);

form.adultGrandTotal.value = (form.adult6Total.value * 1)
+ (form.adult5Total.value * 1)
+ (form.adult4Total.value * 1);


// NOTE: grand total of days
// form.grandSkiingDays.value = (form.infantNumberOfDays.value * form.infantQuantity.value)
// + (form.childGrandSkiingDays.value * 1)
// + (form.adultGrandSkiingDays.value * 1);
// NOTE: grand total of tickets
form.grandQuantity.value = (form.childGrandQuantity.value * 1)
+ (form.adultGrandQuantity.value * 1)
+ (form.seniorQuantity.value * 1);
// NOTE: grand $ total
form.grandTotal.value = (form.childGrandTotal.value * 1)
+ (form.adultGrandTotal.value * 1)
+ (form.seniorTotal.value * 1);
}
</script>


The following is used to calculate the various quanity values.

<select name="child6Quantity" onChange="calculateTotals()">
<script language="javascript">
for(i = 0; i < 26; i++) {
document.write('<option value="' + i + '"> ' + i);
}
</script>
</select>

Thanks,
~cherylw

Mrs G
07-13-2002, 08:27 AM
Could really do with the HTML coding that creates the forms as well.

Would be more helpful in seeing error


Thanks

vertronics
07-14-2002, 02:07 AM
Hi,

Here's the url.. the html is too long to post here.

http://www.edusymp.com/secure/vailVer2daysa.cfm

If you select a quantity, I get a total /category; however,
my grand totals get lost.

Thanks,

~cherylw