Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <!-- Created by Thomas Jones of TomTec Solutions on 12-07-16 @ 2:51pm -->
- <title>Energy to Price Calculator</title>
- <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
- <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
- <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- </head>
- <body>
- <div class="container">
- <form onsubmit="calculateResult()" action="javascript:void(0)">
- <h2>Energy to Price Calculator</h2><br />
- <font color="red"><noscript>JavaScript needs to be enabled for this page to work.</noscript></font>
- <div class="form-horizontal">
- <div class="form-group">
- <label class="control-label col-sm-2" for="pricePerKilowatt">Cents per kWh:</label>
- <div class="col-sm-10">
- <input type="number" class="form-control" id="pricePerKilowatt" value="29">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-2" for="applicanceWattage">Wattage of the appliance:</label>
- <div class="col-sm-10">
- <input type="number" class="form-control" id="applianceWattage">
- </div>
- </div>
- <div class="form-group">
- <label class="control-label col-sm-2" for="hoursRunning">Hours running per day:</label>
- <div class="col-sm-10">
- <input type="number" class="form-control" id="hoursRunning">
- </div>
- </div>
- <div class="form-group">
- <div class="col-sm-offset-2 col-sm-10">
- <button onclick="calculateResult()" id="button" class="btn btn-default">Calculate</button>
- </div>
- </div>
- </div>
- <p id="output" style="text-align: center;">Results show here.</p>
- </form>
- </div>
- <script>
- function calculateResult() {
- var hourlyRunningCost = (parseInt(document.getElementById("applianceWattage").value) / 1000) * parseInt(document.getElementById("pricePerKilowatt").value);
- var dailyRunningCost = parseInt(document.getElementById("hoursRunning").value) * hourlyRunningCost;
- var dailyRunningCostHumanReadable = "$" + (Math.round(dailyRunningCost) / 100);
- if (!dailyRunningCostHumanReadable.endsWith("0")) { var dailyRunningCostHumanReadable = dailyRunningCostHumanReadable + "0"; }
- if (isNaN(dailyRunningCost)) {
- document.getElementById("output").innerHTML = "Please enter numbers only within the text boxes.";
- } else {
- document.getElementById("output").innerHTML = ("Price to run this appliance per day: " + dailyRunningCostHumanReadable);
- }
- }
- </script>
- <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>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement