I would like to auto calculate a price + commission (12%) and automatically input the result. For example: 100$ + 12% commission = 112$. Problem is here my result is 10012.
Where did I write wrong my code:
<input type="value" class="form-control" id="input">
<input type="value" id="output" onkeyup="calc();"/>
<input id="finalprice" onkeyup="calc();"/>
<script>
function calc() {
var a = document.getElementById("input").value;
var b = (12/100) ;
var c = b * 100;
var e = a + c;
var f = a + e;
document.getElementById("output").value = c;
document.getElementById("finalprice").value = f;
}
</script>
.getElementById().value
is working perfectly, but your calculation is going wrong.value
? Simply change it tonumber
and you're all good..type="number"
input's.value
property will still return a string...Number
orparseFloat
then..