How to calculate Calculate Discount prince using javascript?

Calculate Discount in Javascript

File name : index.php

<!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>

Output :-

Price

%








Previous Next


Trending Tutorials




Review & Rating

0.0 / 5

0 Review

5
(0)

4
(0)

3
(0)

2
(0)

1
(0)

Write Review Here