driveflexfuel
New Member
- Messages
- 159
- Reaction score
- 0
- Points
- 0
I have a lot on my plate lately and I do not have time to learn PHP to convert my form over. This form was all on one page and now I am converting it over a small form with a pop up window for results. I am offering 150 credits for anyone that wishes to finish this code for me.
Original Form
This is what i have come up with so far before I ran out of time you can change it any you wish as long as it works.
My work so far
Original Form
Code:
<script type="text/javascript">
function clearMe(formfield)
{
if (formfield.defaultValue==formfield.value)
formfield.value = ""
}
function CurrencyFormatted(amount)
{
var i = parseFloat(amount);
if(isNaN(i)) { i = 0.00; }
var minus = '';
if(i < 0) { minus = '-'; }
i = Math.abs(i);
i = parseInt((i + .005) * 100);
i = i / 100;
s = new String(i);
if(s.indexOf('.') < 0) { s += '.00'; }
if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
s = minus + s;
return s;
}
function Calculate()
{
var GASPrice = document.Calc1.GASPrice.value;
var Ethanol = document.Calc1.Ethanol.value;
var MPGGAS = document.Calc1.MPGGAS.value;
var Tank = document.Calc1.Tank.value;
var MPGE85 = document.Calc1.MPGE85.value;
if (MPGE85 <= 0)
{
var E85Percent = (MPGGAS / (MPGGAS * .87));
}
else
{
var E85Percent = (MPGGAS / MPGE85);
}
var GASTank = (GASPrice * Tank);
var E85 = (Ethanol * 2) / 2;
var E85TankNon = (E85 * Tank);
var E85Tank = ((E85 * Tank) * E85Percent);
var GasSaveTank = (E85Tank - GASTank);
var GasSaveGall = (E85Tank - GASTank) / Tank;
var E85SaveTank = (GASTank - E85Tank);
var E85SaveGall = (GASTank - E85Tank) / Tank;
var Diff = (GASTank - E85Tank);
var SaveTankGas = "$" + CurrencyFormatted(GasSaveTank);
var SaveGallGas = "$" + CurrencyFormatted(GasSaveGall);
var SaveTankE85 = "$" + CurrencyFormatted(E85SaveTank);
var SaveGallE85 = "$" + CurrencyFormatted(E85SaveGall);
var E85Tank1 = "$" + CurrencyFormatted(E85Tank);
var GASTank1 = "$" + CurrencyFormatted(GASTank);
var E85TankNon1 = "$" + CurrencyFormatted(E85TankNon);
if (Diff <= 0)
{
document.Calc1.BestResults.value = "Your Best Choise is using Gasoline";
document.Calc1.SaveTank.value = SaveTankGas;
document.Calc1.SaveGall.value = SaveGallGas;
}
else
{
document.Calc1.BestResults.value = "Your Best Choise is using E85";
document.Calc1.SaveTank.value = SaveTankE85;
document.Calc1.SaveGall.value = SaveGallE85;
}
document.Calc1.GasFill.value = GASTank1;
document.Calc1.E85Fill.value = E85Tank1;
document.Calc1.E85FillNon.value = E85TankNon1;
var GASPriceReturn = CurrencyFormatted(GASPrice);
var EthanolReturn = CurrencyFormatted(Ethanol);
var MPGGASReturn = CurrencyFormatted(MPGGAS);
var TankReturn = CurrencyFormatted(Tank);
var MPGE85Return = CurrencyFormatted(MPGE85);
document.Calc1.GASPrice.value = GASPriceReturn;
document.Calc1.Ethanol.value = EthanolReturn;
document.Calc1.MPGGAS.value = MPGGASReturn;
document.Calc1.Tank.value = TankReturn;
document.Calc1.MPGE85.value = MPGE85Return;
//return false so the form isn't cleared
return false;
}
</script>
<form name ="Calc1" method="post" onSubmit="return Calculate();">
<div id="form">
<table>
<tr>
<td>Price of Gasoline <br /> <span id="box">$<input type="text" name="GASPrice" id="GASPrice" class="txtboxentry" style="text-align:center" onfocus="clearMe(this)" value="0.00"></span></td>
<td>Price of E85 <br /> $<input type="text" name="Ethanol" id="Ethanol" class="txtboxentry" style="text-align:center" onfocus="clearMe(this)" value="0.00"></td>
</tr><tr>
<td>Size of fuel Tank <br /> $<input type="text" name="Tank" id="Tank" class="txtboxentry" style="text-align:center" onfocus="clearMe(this)" value="0.00"></td>
<td>MPG on Gasoline <br /> $<input type="text" name="MPGGAS" id="MPGGAS" class="txtboxentry" style="text-align:center" onfocus="clearMe(this)" value="0.00"></td>
</tr><tr>
<td colspan="2" align="center">MPG on E85 <br /> (if unknown leave 0.00)<br>$<input type="text" name="MPGE85" id="MPGE85" class="txtboxentry" style="text-align:center" onfocus="clearMe(this)" value="0.00"></td>
</tr><tr>
<td colspan="2" align="center"><input type = "submit" value = "Calculate" name="submit" class="cmdbutton"></td>
</td>
</table>
<input type="text" name="BestResults" value="Your Choice Is Using" id="BestResults" class="txtboxwide" style="text-align:center" readonly="readonly">
Savings Per Tank
<input type="text" name="SaveTank" id="SaveTank" class="txtbox1" readonly="readonly">
Savings Per Gallon
<input type="text" name="SaveGall" id="SaveGall" class="txtbox1" readonly="readonly">
<div id="gas_fill">
Cost to fill with Gasoline<input type="text" name="GasFill" id="Test" class="txtbox" readonly="readonly">
</div>
<div id="e85_fill">
Cost to fill with E85<input type="text" name="E85FillNon" id="E85FillNon" class="txtbox" readonly="readonly">
</div>
<div id="e85_fill_adjusted">
Cost to fill with E85 *Adjusted price<input type="text" name="E85Fill" id="E85Fill" class="txtbox" readonly="readonly">
</div>
</form>
* Adjusted Price : The adjusted price includes the extra cost due to loss in fuel mileage.
</div>
</body>
My work so far
Code:
<?php
$GASPrice = strip_tags($_POST["GASPrice"]);
$Ethanol = strip_tags($_POST["Ethanol"]);
$MPGGAS = strip_tags($_POST["MPGGAS"]);
$Tank = strip_tags($_POST["Tank"]);
$MPGE85= strip_tags($_POST["MPGE85"]);
$GASPrice = document.Calc1.GASPrice.value;
$Ethanol = document.Calc1.Ethanol.value;
$MPGGAS = document.Calc1.MPGGAS.value;
$Tank = document.Calc1.Tank.value;
$MPGE85 = document.Calc1.MPGE85.value;
if (MPGE85 <= 0)
$E85Percent = (MPGGAS / (MPGGAS * .87));
else
$E85Percent = (MPGGAS / MPGE85);
$GASTank = (GASPrice * Tank);
$E85 = (Ethanol * 2) / 2;
$E85TankNon = (E85 * Tank);
$E85Tank = ((E85 * Tank) * E85Percent);
$GasSaveTank = (E85Tank - GASTank);
$GasSaveGall = (E85Tank - GASTank) / Tank;
$E85SaveTank = (GASTank - E85Tank);
$E85SaveGall = (GASTank - E85Tank) / Tank;
$Diff = (GASTank - E85Tank);
$SaveTankGas = "$" + CurrencyFormatted(GasSaveTank);
$SaveGallGas = "$" + CurrencyFormatted(GasSaveGall);
$SaveTankE85 = "$" + CurrencyFormatted(E85SaveTank);
$SaveGallE85 = "$" + CurrencyFormatted(E85SaveGall);
$E85Tank1 = "$" + CurrencyFormatted(E85Tank);
$GASTank1 = "$" + CurrencyFormatted(GASTank);
$E85TankNon1 = "$" + CurrencyFormatted(E85TankNon);
if (Diff <= 0)
{
document.Calc1.BestResults.value = "Your Best Choise is using Gasoline";
document.Calc1.SaveTank.value = SaveTankGas;
document.Calc1.SaveGall.value = SaveGallGas;
}
else
{
document.Calc1.BestResults.value = "Your Best Choise is using E85";
document.Calc1.SaveTank.value = SaveTankE85;
document.Calc1.SaveGall.value = SaveGallE85;
}
document.Calc1.GasFill.value = GASTank1;
document.Calc1.E85Fill.value = E85Tank1;
document.Calc1.E85FillNon.value = E85TankNon1;
$GASPriceReturn = CurrencyFormatted(GASPrice);
$EthanolReturn = CurrencyFormatted(Ethanol);
$MPGGASReturn = CurrencyFormatted(MPGGAS);
$TankReturn = CurrencyFormatted(Tank);
$MPGE85Return = CurrencyFormatted(MPGE85);
document.Calc1.GASPrice.value = GASPriceReturn;
document.Calc1.Ethanol.value = EthanolReturn;
document.Calc1.MPGGAS.value = MPGGASReturn;
document.Calc1.Tank.value = TankReturn;
document.Calc1.MPGE85.value = MPGE85Return;
//return false so the form isn't cleared
return false;?>