R
rdavis7408
I am attempting what I would think would be a simple calculation of the
cost of traveling a single mile. But I can not figure this out. The
following is my script. Any help would be appreciated.
I want the user to enter the price per gallon in one textbox, the miles
per gallon in the next textbox and then press the button and get the
cost per gallon by dividing the price per gallon by the miles per
gallon.
Thank you in advance
<HTML>
<HEAD>
<TITLE> "CALCULATE FUEL COST" </TITLE>
<SCRIPT LANGUAGE = "JavaScript">
function fuelCalculator() {
var costpergallon;
costpergallon= document.form1.ppg.value / document.form1.mpg.value;
document.form1.cpg.value = costpergallon;
document.write(costpergallon);
}
</ script>
</head>
<Body>
<form name ="form1">
<input type="text" name="ppg" value=0 /> </br>
<input type="text" name="mpg" value=0 /> </br>
<input type="text" name="cpg" value=0 /> </br>
<input type= "button" value="Calculate" onclick="fuelCalculator();" />
</form>
</body>
</html>
cost of traveling a single mile. But I can not figure this out. The
following is my script. Any help would be appreciated.
I want the user to enter the price per gallon in one textbox, the miles
per gallon in the next textbox and then press the button and get the
cost per gallon by dividing the price per gallon by the miles per
gallon.
Thank you in advance
<HTML>
<HEAD>
<TITLE> "CALCULATE FUEL COST" </TITLE>
<SCRIPT LANGUAGE = "JavaScript">
function fuelCalculator() {
var costpergallon;
costpergallon= document.form1.ppg.value / document.form1.mpg.value;
document.form1.cpg.value = costpergallon;
document.write(costpergallon);
}
</ script>
</head>
<Body>
<form name ="form1">
<input type="text" name="ppg" value=0 /> </br>
<input type="text" name="mpg" value=0 /> </br>
<input type="text" name="cpg" value=0 /> </br>
<input type= "button" value="Calculate" onclick="fuelCalculator();" />
</form>
</body>
</html>