//DO NOT REMOVE THIS COPYWRITE INFO! //Miles Per Gallon Calculator //By Daniel C. Peterson //Web Winder Website Services, 1997-2006 All Rights Reserved. //Distribution, editing or reselling of this script is strictyly prohibited //without expressed written permission from Daniel C. Peterson. //For commercial grade (professional) versions of this and many other //calculators, visit http://www.webwinder.com.
function compute(form) { var milesPerMo = form.avgMiles.value *30.4; var mpgcalc = ((form.endOd.value - form.begOd.value) / form.gallons.value); var moGascalc = (((form.avgMiles.value * 30.4) / mpgcalc) * form.ppGal.value); form.mpg.value = mpgcalc; form.moGas.value = moGascalc; form.yrGas.value = moGascalc * 12;
if(form.mpg2.value > 0) { var moGas2calc = ((milesPerMo / form.mpg2.value) * form.ppGal.value); form.moGas2.value = moGas2calc; form.yrGas2.value = moGas2calc * 12; var annualsave = form.yrGas.value - form.yrGas2.value; form.save.value = ("If you switch to a car that gets " + form.mpg2.value + " mpg, you'll save $" + parseInt(annualsave,10) + " per year.") } else { form.moGas2.value = ""; form.yrGas2.value = ""; form.save.value = ("Now enter a higher mpg to compare to your car's present mpg."); } }
function ClearForm(form) { form.begOd.value = ""; form.endOd.value = ""; form.avgMiles.value = ""; form.gallons.value = ""; form.ppGal.value = ""; form.mpg.value = ""; form.moGas.value = ""; form.yrGas.value = ""; form.mpg2.value = ""; form.moGas2.value = ""; form.yrGas2.value = ""; form.save.value = "";
}