Sales tax calculator html code - Html code with java script sales tax html code
Here is a code for Sales tax calculator
<html>
<head>
<title>Sales Tax Calculator</title>
<style>
.container {
width: 300px;
margin: 0 auto;
}
.input-field {
margin-bottom: 10px;
}
</style>
</head>
<body>
<div class="container">
<h2>Sales Tax Calculator</h2>
<div class="input-field">
<label for="subtotal">Subtotal:</label>
<input id="subtotal" min="0" step="0.01" type="number" />
</div>
<div class="input-field">
<label for="taxRate">Tax Rate (%):</label>
<input id="taxRate" min="0" step="0.01" type="number" />
</div>
<div class="input-field">
<button onclick="calculateTax()">Calculate</button>
</div>
<div class="input-field">
<label for="total">Total:</label>
<input id="total" readonly="" type="text" />
</div>
</div>
<script>
function calculateTax() {
var subtotal = document.getElementById("subtotal").value;
var taxRate = document.getElementById("taxRate").value;
// Perform validation
if (subtotal === "" || taxRate === "") {
alert("Please enter a subtotal and tax rate.");
return;
}
var taxAmount = (subtotal * (taxRate / 100)).toFixed(2);
var total = (parseFloat(subtotal) + parseFloat(taxAmount)).toFixed(2);
document.getElementById("total").value = total;
}
</script>
</body>
Comments
Post a Comment