Need help with a script for calculating

Discussion in 'Programming' started by genius, Oct 24, 2009.

  1. #1
    Hello,

    I'm design a PVC windows site , and I need to build something that will give you the price for the window based on the dimensions inserted.So the user should insert height , lenght and the script should deliver the price..How can I do this ? I really need your help...

    Thank you.
     
    genius, Oct 24, 2009 IP
  2. organicCyborg

    organicCyborg Peon

    Messages:
    330
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    I assume you're going to charge by the square foot.

    User would input height in inches, and the width in inches. Then just multiply the two to get the area in sq. inches. You can do the math yourself.

    If you're doing it in PHP, check out this site: http://www.w3schools.com/php/php_forms.asp for a tutorial for working with forms.
     
    organicCyborg, Oct 25, 2009 IP
  3. FCM

    FCM Well-Known Member

    Messages:
    669
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    155
    #3
    I'm not free but rep would be nice ;) J/K here is a solution.

    
    <!-- YOUR FORM -->
    <form action="?calculate" method="get">
    Height : <input type="text" name="h"  /> <br />
    Width  : <input type="text" name="w" /> <br />
    <input type="submit" value="calculate">
    </form>
    
    <!-- THE CODE TO CALCULATE COST -->
    <?php
    // SET HOW MUCH PER SQUARE FOOT
    $price_per_sqfoot = '1.00';
    
    if( !$_GET["h"] and !$_GET["w"] ){
    You need to set the values
    }
    else
    {
    $total_sq= $_GET["h"]*$_GET["w"];
    $total_cost = $total_sq*$price_per_sqfoot;
    
    // output result
    echo "Your total cost: $total_cost";
    }
    ?>
    
    Code (markup):
    I wrote that entirely from my head, I didn't test it but it is fairly simple. Should work.
     
    FCM, Oct 25, 2009 IP
  4. genius

    genius Well-Known Member

    Messages:
    535
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #4
    When I hit calculate it just resets itself ...:confused: , can you help me with it ?
     
    genius, Oct 25, 2009 IP
  5. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #5
    Or in javascript:
    
    Height (ft) : <input id="txtHeight" type="text" /><br />
    Width (ft)  : <input id="txtWidth" type="text" /><br />
    <input id="calculate" type="button" value="Calcultate">
    <div id="result"></div>
    <script type="text/javascript">
    document.getElementById("calculate").onclick=function() {
    	var cost = "12.10";   //Cost per square ft
    	var totalCost = Math.round(document.getElementById("txtHeight").value * document.getElementById("txtWidth").value * 
    
    cost * 100) / 100;
    	document.getElementById("result").innerHTML = "$" + totalCost;
    }
    </script>
    
    Code (markup):
     
    camjohnson95, Oct 25, 2009 IP
  6. FCM

    FCM Well-Known Member

    Messages:
    669
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    155
    #6
    This is php make sure you are not running it as .html
    Other then that I will PM you with something.
     
    FCM, Oct 25, 2009 IP
  7. genius

    genius Well-Known Member

    Messages:
    535
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    108
    #7
    Sorry for the delay but it's not working...it's saved as calc.php
     
    genius, Oct 29, 2009 IP