So i need an order form that automatically calculates totals as its filled in.
I am useless with JavaScript so i googled for a tut and found one that was easy to follow and covered my needs (kind of). However it was for a form with 2 products with 2 options each.
I have scaled up the script to handle my needs, but its now bloated crap. I am sure this could be condensed into a few lines of code with some kind of loop / array, but i suck at javascript.
The js:
I am useless with JavaScript so i googled for a tut and found one that was easy to follow and covered my needs (kind of). However it was for a form with 2 products with 2 options each.
I have scaled up the script to handle my needs, but its now bloated crap. I am sure this could be condensed into a few lines of code with some kind of loop / array, but i suck at javascript.
The js:
Code:
/*money formating*/
function dm(amount)
{
string = "" + amount;
dec = string.length - string.indexOf('.');
if (string.indexOf('.') == -1)
return string + '.00';
if (dec == 1)
return string + '00';
if (dec == 2)
return string + '0';
if (dec > 3)
return string.substring(0,string.length-dec+3);
return string;
}
/*calculator*/
function calculate()
{
QtyLounge = 0; QtyDinningroom = 0; QtyKitchen = 0; QtyUtility = 0; QtyConservatory = 0; QtyDoublebedroom = 0; QtySinglebedroom = 0; QtyEnsuite = 0; QtyBathroom = 0; QtyPorch = 0; QtyCloakroom = 0; QtyHall = 0; QtyStairs = 0; QtyLanding = 0;
TotLounge = 0; TotDinningroom = 0; TotKitchen = 0; TotUtility = 0; TotConservatory = 0; TotDoublebedroom = 0; TotSinglebedroom = 0; TotEnsuite = 0; TotBathroom = 0; TotPorch = 0; TotCloakroom = 0; TotHall = 0; TotStairs = 0; TotLanding = 0;
SizeLounge = 0; SizeDinningroom = 0; SizeKitchen = 0; SizeUtility = 0; SizeConservatory = 0; SizeDoublebedroom = 0; SizeSinglebedroom = 0; SizeEnsuite = 0; SizeBathroom = 0; SizePorch = 0; SizeCloakroom = 0; SizeHall = 0; SizeStairs = 0; SizeLanding = 0;
CleanType = 0;
/*get clean type choosen*/
if (document.ofrm.cleanType.value > "")
{ CleanType = document.ofrm.cleanType.value };
document.ofrm.cleanType.value = eval(CleanType);
SelectedPrice = CleanType
/*end clean type selection*/
/*get size values*/
if (document.ofrm.sizeLounge.value > "")
{ SizeLounge = document.ofrm.sizeLounge.value };
document.ofrm.sizeLounge.value = eval(SizeLounge);
if (document.ofrm.sizeDinningroom.value > "")
{ SizeDinningroom = document.ofrm.sizeDinningroom.value };
document.ofrm.sizeDinningroom.value = eval(SizeDinningroom);
if (document.ofrm.sizeKitchen.value > "")
{ SizeKitchen = document.ofrm.sizeKitchen.value };
document.ofrm.sizeKitchen.value = eval(SizeKitchen);
if (document.ofrm.sizeUtility.value > "")
{ SizeUtility = document.ofrm.sizeUtility.value };
document.ofrm.sizeUtility.value = eval(SizeUtility);
if (document.ofrm.sizeConservatory.value > "")
{ SizeConservatory = document.ofrm.sizeConservatory.value };
document.ofrm.sizeConservatory.value = eval(SizeConservatory);
if (document.ofrm.sizeDoublebedroom.value > "")
{ SizeDoublebedroom = document.ofrm.sizeDoublebedroom.value };
document.ofrm.sizeDoublebedroom.value = eval(SizeDoublebedroom);
if (document.ofrm.sizeSinglebedroom.value > "")
{ SizeSinglebedroom = document.ofrm.sizeSinglebedroom.value };
document.ofrm.sizeSinglebedroom.value = eval(SizeSinglebedroom);
if (document.ofrm.sizeEnsuite.value > "")
{ SizeEnsuite = document.ofrm.sizeEnsuite.value };
document.ofrm.sizeEnsuite.value = eval(SizeEnsuite);
if (document.ofrm.sizeBathroom.value > "")
{ SizeBathroom = document.ofrm.sizeBathroom.value };
document.ofrm.sizeBathroom.value = eval(SizeBathroom);
if (document.ofrm.sizePorch.value > "")
{ SizePorch = document.ofrm.sizePorch.value };
document.ofrm.sizePorch.value = eval(SizePorch);
if (document.ofrm.sizeCloakroom.value > "")
{ SizeCloakroom = document.ofrm.sizeCloakroom.value };
document.ofrm.sizeCloakroom.value = eval(SizeCloakroom);
if (document.ofrm.sizeHall.value > "")
{ SizeHall = document.ofrm.sizeHall.value };
document.ofrm.sizeHall.value = eval(SizeHall);
if (document.ofrm.sizeStairs.value > "")
{ SizeStairs = document.ofrm.sizeStairs.value };
document.ofrm.sizeStairs.value = eval(SizeStairs);
if (document.ofrm.sizeLanding.value > "")
{ SizeLanding = document.ofrm.sizeLanding.value };
document.ofrm.sizeLanding.value = eval(SizeLanding);
/*End size values*/
/*Get quantity values*/
if (document.ofrm.qtyLounge.value > "")
{ QtyLounge = document.ofrm.qtyLounge.value };
document.ofrm.qtyLounge.value = eval(QtyLounge);
if (document.ofrm.qtyDinningroom.value > "")
{ QtyDinningroom = document.ofrm.qtyDinningroom.value };
document.ofrm.qtyDinningroom.value = eval(QtyDinningroom);
if (document.ofrm.qtyKitchen.value > "")
{ QtyKitchen = document.ofrm.qtyKitchen.value };
document.ofrm.qtyKitchen.value = eval(QtyKitchen);
if (document.ofrm.qtyUtility.value > "")
{ QtyUtility = document.ofrm.qtyUtility.value };
document.ofrm.qtyUtility.value = eval(QtyUtility);
if (document.ofrm.qtyConservatory.value > "")
{ QtyConservatory = document.ofrm.qtyConservatory.value };
document.ofrm.qtyConservatory.value = eval(QtyConservatory);
if (document.ofrm.qtyDoublebedroom.value > "")
{ QtyDoublebedroom = document.ofrm.qtyDoublebedroom.value };
document.ofrm.qtyDoublebedroom.value = eval(QtyDoublebedroom);
if (document.ofrm.qtySinglebedroom.value > "")
{ QtySinglebedroom = document.ofrm.qtySinglebedroom.value };
document.ofrm.qtySinglebedroom.value = eval(QtySinglebedroom);
if (document.ofrm.qtyEnsuite.value > "")
{ QtyEnsuite = document.ofrm.qtyEnsuite.value };
document.ofrm.qtyEnsuite.value = eval(QtyEnsuite);
if (document.ofrm.qtyBathroom.value > "")
{ QtyBathroom = document.ofrm.qtyBathroom.value };
document.ofrm.qtyBathroom.value = eval(QtyBathroom);
if (document.ofrm.qtyPorch.value > "")
{ QtyPorch = document.ofrm.qtyPorch.value };
document.ofrm.qtyPorch.value = eval(QtyPorch);
if (document.ofrm.qtyCloakroom.value > "")
{ QtyCloakroom = document.ofrm.qtyCloakroom.value };
document.ofrm.qtyCloakroom.value = eval(QtyCloakroom);
if (document.ofrm.qtyHall.value > "")
{ QtyHall = document.ofrm.qtyHall.value };
document.ofrm.qtyHall.value = eval(QtyHall);
if (document.ofrm.qtyStairs.value > "")
{ QtyStairs = document.ofrm.qtyStairs.value };
document.ofrm.qtyStairs.value = eval(QtyStairs);
if (document.ofrm.qtyLanding.value > "")
{ QtyLanding = document.ofrm.qtyLanding.value };
document.ofrm.qtyLanding.value = eval(QtyLanding);
/*End quantity values*/
/*Set row totals*/
TotLounge = QtyLounge * SelectedPrice * SizeLounge;
document.ofrm.totalLounge.value = dm(eval(TotLounge));
TotDinningroom = QtyDinningroom * SelectedPrice * SizeDinningroom;
document.ofrm.totalDinningroom.value = dm(eval(TotDinningroom));
TotKitchen = QtyKitchen * SelectedPrice * SizeKitchen;
document.ofrm.totalKitchen.value = dm(eval(TotKitchen));
TotUtility = QtyUtility * SelectedPrice * SizeUtility;
document.ofrm.totalUtility.value = dm(eval(TotUtility));
TotConservatory = QtyConservatory * SelectedPrice * SizeConservatory;
document.ofrm.totalConservatory.value = dm(eval(TotConservatory));
TotDoublebedroom = QtyDoublebedroom * SelectedPrice * SizeDoublebedroom;
document.ofrm.totalDoublebedroom.value = dm(eval(TotDoublebedroom));
TotSinglebedroom = QtySinglebedroom * SelectedPrice * SizeSinglebedroom;
document.ofrm.totalSinglebedroom.value = dm(eval(TotSinglebedroom));
TotEnsuite = QtyEnsuite * SelectedPrice * SizeEnsuite;
document.ofrm.totalEnsuite.value = dm(eval(TotEnsuite));
TotBathroom = QtyBathroom * SelectedPrice * SizeBathroom;
document.ofrm.totalBathroom.value = dm(eval(TotBathroom));
TotPorch = QtyPorch * SelectedPrice * SizePorch;
document.ofrm.totalPorch.value = dm(eval(TotPorch));
TotCloakroom = QtyCloakroom * SelectedPrice * SizeCloakroom;
document.ofrm.totalCloakroom.value = dm(eval(TotCloakroom));
TotHall = QtyHall * SelectedPrice * SizeHall;
document.ofrm.totalHall.value = dm(eval(TotHall));
TotStairs = QtyStairs * SelectedPrice * SizeStairs;
document.ofrm.totalStairs.value = dm(eval(TotStairs));
TotLanding = QtyLanding * SelectedPrice * SizeLanding;
document.ofrm.totalLanding.value = dm(eval(TotLanding));
/*End row totals*/
/*Set quote total (Totamt)*/
Totamt =
eval(TotLounge) +
eval(TotDinningroom) +
eval(TotKitchen) +
eval(TotUtility) +
eval(TotConservatory) +
eval(TotDoublebedroom) +
eval(TotSinglebedroom) +
eval(TotEnsuite) +
eval(TotBathroom) +
eval(TotPorch) +
eval(TotCloakroom) +
eval(TotHall) +
eval(TotStairs) +
eval(TotLanding) ;
/*VAT calculation*/
TotAll = Totamt * 1.175 ;
document.ofrm.GrandTotal.value = dm(eval(TotAll));
/*End quote tatl*/