I'm having trouble figuring out how the input calculation works with Jquey.
I'll show the following example:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<input type="text" name="campo_1" class="campo_1">
<input type="text" name="campo_2" class="campo_2">
<input type="text" name="res_1" class="res_1">
<!-- Resultado de campo_1 * campo_2 -->
<input type="text" name="campo_3" class="campo_3">
<input type="text" name="campo_4" class="campo_4">
<input type="text" name="res_2" class="res2">
<!-- Resultado de campo_3 * campo_4 -->
<input type="text" name="res_3" class="res3">
<!-- Resultado de campo_1 + campo_2 + campo_3 + campo_4 -->
</body>
</html>
I do not know, I have no idea how to do that when you put values in the fields, if you get the result.
I have made adaptations in other projects of the type:
<script type="text/javascript">
function updateTotal_836() {
var total_836 = 0;
var list_836 = document.getElementsByClassName("input[836]");
var values = [];
for(var i = 0; i < list_836.length; ++i) {
values.push(parseFloat(list_836[i].value));
}
total_836 = values.reduce(function(previousValue, currentValue, index, array){
return previousValue * currentValue;
});
if(isNaN(parseFloat(total_836))){
document.getElementById("valor_total[836]").value = 0;
}else{
document.getElementById("valor_total[836]").value = total_836;
}
}
</script>
But I do not understand how it starts and more or less how it ends. I'm digging into Jquery, but I admit that I need help.
Thank you.
It worked, but there was a problem.
I made this calculation:
$('input[name="rec_vista"]').change(function(e) {
if (!$('input[name="rec_vista"]').val()) {
$('input[name="rec_vista"]').val(0);
}
var rec_vista = parseFloat($('input[name="rec_vista"]').val());
a_vista = rec_vista + 10;
$('input[name="a_vista"]').val(a_vista);
});
If I put 1,000,000 in the input, instead of calculating 1,010.00, it calculates 11.
I put, I took parentheses, but nothing to improve this crazy sum.
If someone can give me a light one last time, I thank you.