Advertisement
tjone270

Energy > Price Calculator

Jul 12th, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 3.14 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <!-- Created by Thomas Jones of TomTec Solutions on 12-07-16 @ 2:51pm -->
  5.     <title>Energy to Price Calculator</title>
  6.     <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  7.     <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  8.     <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  9.     <meta charset="utf-8">
  10.     <meta name="viewport" content="width=device-width, initial-scale=1">
  11.   </head>
  12.   <body>
  13.     <div class="container">
  14.       <form onsubmit="calculateResult()" action="javascript:void(0)">
  15.         <h2>Energy to Price Calculator</h2><br />
  16.         <font color="red"><noscript>JavaScript needs to be enabled for this page to work.</noscript></font>
  17.         <div class="form-horizontal">
  18.           <div class="form-group">
  19.             <label class="control-label col-sm-2" for="pricePerKilowatt">Cents per kWh:</label>
  20.             <div class="col-sm-10">
  21.               <input type="number" class="form-control" id="pricePerKilowatt" value="29">
  22.             </div>
  23.           </div>
  24.           <div class="form-group">
  25.             <label class="control-label col-sm-2" for="applicanceWattage">Wattage of the appliance:</label>
  26.             <div class="col-sm-10">
  27.               <input type="number" class="form-control" id="applianceWattage">
  28.             </div>
  29.           </div>
  30.           <div class="form-group">
  31.             <label class="control-label col-sm-2" for="hoursRunning">Hours running per day:</label>
  32.             <div class="col-sm-10">
  33.               <input type="number" class="form-control" id="hoursRunning">
  34.             </div>
  35.           </div>
  36.           <div class="form-group">
  37.             <div class="col-sm-offset-2 col-sm-10">
  38.               <button onclick="calculateResult()" id="button" class="btn btn-default">Calculate</button>
  39.             </div>
  40.           </div>
  41.         </div>
  42.         <p id="output" style="text-align: center;">Results show here.</p>
  43.       </form>
  44.     </div>
  45.     <script>
  46.       function calculateResult() {
  47.         var hourlyRunningCost = (parseInt(document.getElementById("applianceWattage").value) / 1000) * parseInt(document.getElementById("pricePerKilowatt").value);
  48.         var dailyRunningCost = parseInt(document.getElementById("hoursRunning").value) * hourlyRunningCost;
  49.         var dailyRunningCostHumanReadable = "$" + (Math.round(dailyRunningCost) / 100);
  50.         if (!dailyRunningCostHumanReadable.endsWith("0")) { var dailyRunningCostHumanReadable = dailyRunningCostHumanReadable + "0"; }
  51.         if (isNaN(dailyRunningCost)) {
  52.           document.getElementById("output").innerHTML = "Please enter numbers only within the text boxes.";
  53.         } else {
  54.           document.getElementById("output").innerHTML = ("Price to run this appliance per day: " + dailyRunningCostHumanReadable);
  55.         }
  56.       }
  57.     </script>
  58.     <footer style="text-align: center">Made with <font color="red"></font> by <font color="blue">tjone270</font>.<br /><a href="http://pastebin.com/UN8iz8hB">Source Code</a></footer>
  59.   </body>
  60. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement