Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Oct 2011
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Please help build small calculator.

    Hello People.

    I would like to build a small calculator in php for my website.

    Basically what it does is give a form to the user that looks like this


    The formula is as follows.
    number_from_box1
    *
    number_from_box2

    =result1

    then take result1
    *52

    =result2

    now take 60,000
    /result2

    =result3

    Take result3 and make it a number with only 2 decimal places
    =result4

    Then display the result on the form like this

    Your warranty would be "result4" years

    I know that there are some really good coders on here. Please could one of you talented people tell me what is the php to do the above on my site?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,546
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    I would say this is javascripting, not PHP ... at least for the interactive calculation.
    So you would not need to "click for warrantee". The value would adjust in real time
    as the numbers are entered or changed. The button on the bottom of the form would
    be to continue-on with the script, as the user would already know what the warrantee is.

    Look on Google for a javascript (or JQuery) form calculator.

  • Users who have thanked mlseim for this post:

    AirfieldCards (04-15-2012)

  • #3
    New Coder
    Join Date
    Oct 2011
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts
    Thanks for your reply mlseim. I'm only just getting started with PHP. Trying to learn javascript instead would be like trying to teach a fish how to ride a bike.

    Please forgive me, I'm an old fart.

  • #4
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,546
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    Save this as "test.html" and view it with your browser ...

    PHP Code:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
        <
    meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
        <
    title>Warrantee Form</title>
    </
    head>
    <
    script type="text/javascript">
    function 
    calculateTotal(){
    var 
    document.getElementById("hours");
    var 
    document.getElementById("days"); 
    var 
    selectedHours h.options[h.selectedIndex].value
    var 
    selectedDays d.options[d.selectedIndex].value;

        var 
    warrAnt 60000/((selectedDays selectedHours)*52);
        var 
    years addDecimalPlaces(warrAnt);
        
        
    //display the result
        
    var divobj document.getElementById('totalPrice');
        
    divobj.style.display='block';
        
    divobj.innerHTML "Warrantee - Number of Years: "+years;
    }
    function 
    hideTotal(){
        var 
    divobj document.getElementById('totalPrice');
        
    divobj.style.display='none';
    }
    function 
    roundNumber(numdec) {
        var 
    result Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
        return 
    result;
    }
    function 
    addDecimalPlaces(myCash) {
           
    myCash myCash 1// Confirm that myCash is a number
           
    myCash myCash.toFixed(2);
           return 
    myCash;
    }
    </script>

    <style>
    #wrap{
        width:400px;
        margin:0 auto;
        text-align:left;
        margin-top:8px;
        padding:5px;
        background:#fff;
        font-family:AvenirLTStd, Arial, Helvetica, sans-serif;
        font-size:13px;    
        line-height:16px;
    }
    #wrap .cont_details fieldset,.cont_order fieldset{
        margin:10px;
        padding:20px;
        -moz-border-radius: 10px;
        -webkit-border-radius: 10px;
        -khtml-border-radius: 10px;
        border-radius: 10px;
    }
    #wrap legend{
        font-size:16px;
        font-family:Georgia, "Times New Roman", Times, serif;
        color:#000;
        font-weight:bold;
        font-style:italic;
        padding-bottom:10px;
    }
    #wrap .cont_details input{
        margin-bottom:10px;
        color:#000;
    }
    #wrap .input1:hover,.input1:active{
        
    }
    #wrap label{
        display:block;
        font-size:12px;
        color:#000;
        font-weight:bold;
    }
    #wrap label.inlinelabel
    {
        display:inline;
    }
    #wrap .cont_order input{
        margin-bottom:5px;
    }
    #wrap .cont_order p{
        padding-top:5px;
    }

    #wrap input[type="radio"]
    {
    margin-top:8px;
    margin-bottom:8px;
    }

    #wrap input[type="text"]:hover,
    #wrap input[type="text"]:active {
    background-color: #FAF398;
    }

    #wrap input#submit
    {
    margin:10px;
    padding-left:20px;
    padding-right:20px;
    padding-top:10px;
    padding-bottom:10px;
    }

    #wrap div#totalPrice
    {
        padding:10px;
        font-weight:bold;
        background-color:#ff0;
    }

    #wrap label.radiolabel
    {
    font-weight:normal;
     display:inline;
    }
    </style>
    <body onload='hideTotal()'>
        <div id="wrap">
            <form action="" id="warrantee" onsubmit="return false;">
            <div>
                <div class="cont_order">
                   <fieldset>
                    <legend>Warrantee Calculator</legend>
                    <label >Hours a Day That You Work</label>
                    <select id="hours" name="hours" onchange="calculateTotal()">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    <option value="8">8</option>
                    <option value="9">9</option>
                    <option value="10">10</option>
                    <option value="11">11</option>
                    <option value="12">12</option>
                    <option value="13">13</option>
                    <option value="14">14</option>
                    <option value="15">15</option>
                    <option value="16">16</option>
                    <option value="17">17</option>
                    <option value="18">18</option>
                    <option value="19">19</option>
                    <option value="20">20</option>
                    <option value="21">21</option>
                    <option value="22">22</option>
                    <option value="23">23</option>
                    <option value="24">24</option>
                    </select>
                    <br/><br />
                    <label >Days Per Week That You Work</label>
             <select id="days" name="days" onchange="calculateTotal()">
                    <option value="1">1</option>
                    <option value="2">2</option>
                    <option value="3">3</option>
                    <option value="4">4</option>
                    <option value="5">5</option>
                    <option value="6">6</option>
                    <option value="7">7</option>
                    </select>
                    <br/><br/>
     
                    <div id="totalPrice"></div>
                    
                    </fieldset>
                </div>
      
                <input type='submit' id='submit' value='submit' onclick="calculateTotal()" />
            </div>  
           </form>
        </div><!--End of wrap-->

    </body>
    </html> 


    .

  • Users who have thanked mlseim for this post:

    AirfieldCards (04-15-2012)

  • #5
    New Coder
    Join Date
    Oct 2011
    Posts
    20
    Thanks
    4
    Thanked 0 Times in 0 Posts
    You absolute star mlseim. That is awesome mate, cheers.
    Now working in my page. http://greeneru.co.uk/warranty.php


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •