Computes the miles per gallon of your car via the miles traveled and the number of gallons used. Also, if you enter the cost per gallon and how many miles you drive a day, it will estimate your monthly and yearly gas expenses.
Add the below code to the <body> section of your page:
<scriptlanguage="javascript"type="text/javascript"> /* Visit http://www.yaldex.com/
for full source code
and get more free JavaScript, CSS and DHTML scripts! */
<!-- Begin function
compute(form){ var
milesPerMo =form.avgMiles.value*30.4; var
mpgcalc =(form.milesDriven.value/form.gallons.value)*1; var
moGascalc =(((form.avgMiles.value*30.4)/
mpgcalc)*form.ppGal.value)*1; mpgcalc =
twoDecs(mpgcalc); moGascalc =
twoDecs(moGascalc); form.mpg.value=
mpgcalc; form.moGas.value=
moGascalc; form.yrGas.value=
moGascalc *12;
} function
twoDecs(item){ returneval(parseInt(item*100)*.01);
} // End --> </script> <form> <tableborder=1>
<tr><td>Miles Driven: </td><td><inputtype=textname=milesDrivensize=5>
mi.</td></tr>
<tr><td>Gallons of Gas: </td><td><inputtype=textname=gallonssize=5>
gal</td></tr>
<tr><td>Cost per Gallon: </td><td>$
<inputtype=textname=ppGalsize=5></td></tr>
<tr><td>Miles per Day: </td><td><inputtype=textname=avgMilessize=5></td></tr>
<tr><tdcolspan=2align=center><inputtype=buttonvalue="Calculates
To...."onClick="compute(this.form)"></td></tr>
<tr><td>~ <inputtype=textname=mpgsize=7></td><td>Mi.
per Gal.</td></tr>
<tr><td>$ <inputtype=textname=moGassize=7></td><td>
per month</td></tr>
<tr><td>$ <inputtype=textname=yrGassize=7></td><td>
per year</td></tr>
<tr>
<td
colspan=2align=center><inputtype=reset></td></tr>
</table> </form>