1
Hello, I need to do a toll calculation based on the kilogram. Each 100kg the toll value should be added
Ex:
50kg = 6.42
100kg = 6.42
101kg = 12.84
200kg = 12.84
299kg = 12.84
300kg = 19.26
...
$(document).ready(function () {
$("#pesoTotaldaNota").focusout(function() {
peso = "20.000"; // = 20Kg
echoPedagio = "6.42"
});
});
I need to show the result on input
<input name="pedagio" type="text" class="form-control" id="pedagio" value="" required>
Another example Até 100kg = 6.42
Até 200kg = 6.42+6.42
Até 200kg = 6.42+6.42+6.42
worked, but I noticed a problem when the value is less than 100. See http://jsfiddle.net/zohfk3rq/
– Tiago
And what you want to happen when the weight is less than 100 ?
– Diego Souza
Another example
Até 100kg = 6.42
Até 200kg = 6.42+6.42
Até 200kg = 6.42+6.42+6.42
– Tiago
I changed the function.
– Diego Souza
Thank you very much diego, but it worked better here http://jsfiddle.net/3b7b5jzm/1/
– Tiago
You’re the boss, man. (y)
– Diego Souza
Your answer is fine, but I think your mistake lies in multiplying the toll by the rest. If there is rest, just include 1 toll value (ie:
valor = valor + echoPedagio
), because it means that the weight has already exceeded a multiple of 100 and a new toll should be added (from what I understand the question). It will be the case of the value 101, for example.– Luiz Vieira