discount to item javascript code example
Example: how to calculate balance automatically using javascript and php using cash paid
<!Doctype html>
<html>
<body>
<input id="price">Price
<br><br>
<input id="discount">%
<br><br>
<button onclick="getPrice()">
Get total
</button>
<br><br>
<input readonly id="total">
<script>
getPrice = function() {
var numVal1 = Number(document.getElementById("price").value);
var numVal2 = Number(document.getElementById("discount").value) / 100;
var totalValue = numVal1 - (numVal1 * numVal2)
document.getElementById("total").value = totalValue.toFixed(2);
}
</script>
</body>
</html>