+ Reply to Thread
Results 1 to 4 of 4

Thread: Javascript form to PHP

  1. #1
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Javascript form to PHP

    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
    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>
    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
    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;?>

  2. #2
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Re: Javascript form to PHP

    Try this I hope it works.
    PHP Code:
    <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
    Don't get me wrong as I believe if and when I help someone I also help myself whereby whatever someone learns I also learn.

    But I will also accept credits or reps if you really want to part with it.

  3. #3
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Re: Javascript form to PHP

    I worked with a couple members in programming help board to create the form.

    You can close this thread.

  4. #4
    dickey's Avatar
    dickey is offline x10 Sophmore dickey is an unknown quantity at this point
    Join Date
    Sep 2008
    Location
    Singapore
    Posts
    128

    Re: Javascript form to PHP

    My message got truncated. anyway you can close your own thread by clicking the option to close thread.

    if you want what I have done you can pm me.
    Don't get me wrong as I believe if and when I help someone I also help myself whereby whatever someone learns I also learn.

    But I will also accept credits or reps if you really want to part with it.

+ Reply to Thread

Similar Threads

  1. Form to email using PHP scripting
    By jayuk666 in forum Free Hosting
    Replies: 2
    Last Post: 10-28-2008, 05:49 AM
  2. PHP contact form styling (line spacing)
    By xxll_martin_llxx in forum Programming Help
    Replies: 3
    Last Post: 07-24-2008, 10:09 AM
  3. include php within javascript
    By thezone1 in forum Programming Help
    Replies: 5
    Last Post: 04-24-2008, 12:50 PM
  4. Replies: 3
    Last Post: 03-10-2008, 12:22 PM
  5. PHP + Javascript Scripts
    By HabSite in forum The Marketplace
    Replies: 1
    Last Post: 10-02-2007, 10:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers