R
rdavis7408
Hello, I have four textboxes that the user enters the price per gallon
paid at the pump, the mileage per gallon and I would like to then
calculate the cost per gallon and use a switch statement to pull a
value based on the price per gallon.
For example if the price of fuel is 2.44 per gallon and the enter that
they get 5.9 miles per gallon the cost of that mile is $.41. Then based
on the cost per gallon of 2.44 we might pay them another $.20 per
gallon based off of the numbers in the switch statement.
The calculation worked until I added the switch statement. Why is that?
Can anyone help?
Thanks ahead of time. Below is the script:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<link href="fsc.css" rel="stylesheet" type="text/css">
</head>
<body>
<script language="JavaScript">
function FuelCalculator(f)
{
var A;
A= Math.round((f.ppg.value/f.mpg.value)*100);
f.cpg.value = "$"+(A/100);
}
var b;
b=this.form.ppg.value
switch(b)
{
Case >=1.25 && <=1.30:
this.form.dlnt.value=.01;
Case >=1.31 && <=1.369:
this.form.dlnt.value=.02;
Case >=1.37 && <=1.429:
this.form.dlnt.value=.03;
default:
this.form.dlnt.value=.99
}
</script>
<form action="">
<table width="351">
<tr>
<td width="213"> Cents per gallon:</td>
<td width="60" > <input name="ppg" type="text"
style="text-align:center" value="0" size="10">
</td>
</tr>
<tr>
<td>Miles per gallon:</td>
<td> <input name="mpg" type="text" value="0" size="10"
style="text-align:center">
</td>
</tr>
<tr>
<td>Fuel Cost Per Mile: </td>
<td > <input name="cpg" type= "text" disabled="true" value="0"
size="10" style="text-align:center">
</td>
<tr>
<td>Dillon Fuel Surcharge Payment: </td>
<td> <input name="dlnt" type="text" disabled="true" value="0"
size="10" style="text-align:center">
</td>
<tr>
<td colspan="2" ><input name="button" type="button"
onClick="FuelCalculator(this.form);" value="Calclulate"> </td>
</tr>
<td><input name="FSC" type="button" onClick="switch(b)"
value="FSC"></td>
</table>
</form>
</body>
</html>
paid at the pump, the mileage per gallon and I would like to then
calculate the cost per gallon and use a switch statement to pull a
value based on the price per gallon.
For example if the price of fuel is 2.44 per gallon and the enter that
they get 5.9 miles per gallon the cost of that mile is $.41. Then based
on the cost per gallon of 2.44 we might pay them another $.20 per
gallon based off of the numbers in the switch statement.
The calculation worked until I added the switch statement. Why is that?
Can anyone help?
Thanks ahead of time. Below is the script:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
<link href="fsc.css" rel="stylesheet" type="text/css">
</head>
<body>
<script language="JavaScript">
function FuelCalculator(f)
{
var A;
A= Math.round((f.ppg.value/f.mpg.value)*100);
f.cpg.value = "$"+(A/100);
}
var b;
b=this.form.ppg.value
switch(b)
{
Case >=1.25 && <=1.30:
this.form.dlnt.value=.01;
Case >=1.31 && <=1.369:
this.form.dlnt.value=.02;
Case >=1.37 && <=1.429:
this.form.dlnt.value=.03;
default:
this.form.dlnt.value=.99
}
</script>
<form action="">
<table width="351">
<tr>
<td width="213"> Cents per gallon:</td>
<td width="60" > <input name="ppg" type="text"
style="text-align:center" value="0" size="10">
</td>
</tr>
<tr>
<td>Miles per gallon:</td>
<td> <input name="mpg" type="text" value="0" size="10"
style="text-align:center">
</td>
</tr>
<tr>
<td>Fuel Cost Per Mile: </td>
<td > <input name="cpg" type= "text" disabled="true" value="0"
size="10" style="text-align:center">
</td>
<tr>
<td>Dillon Fuel Surcharge Payment: </td>
<td> <input name="dlnt" type="text" disabled="true" value="0"
size="10" style="text-align:center">
</td>
<tr>
<td colspan="2" ><input name="button" type="button"
onClick="FuelCalculator(this.form);" value="Calclulate"> </td>
</tr>
<td><input name="FSC" type="button" onClick="switch(b)"
value="FSC"></td>
</table>
</form>
</body>
</html>