I'm trying to create a function that add automatically value of the current element into another selector, something like this:
function calculate(current,selector) {
var sum = $(selector).val();
if (!isNaN($(current).value) && $(current).value.length != 0) {
sum += parseFloat($(current).value);
}
$(selector).val(sum.toFixed(2));
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="text" id="one" onkeyup="calculate(this,'#three')" >
<input type="text" id="two" onkeyup="calculate(this,'#five')" >
<input type="text" id="three">
<input type="text" id="five">