I have these form, which does the calculation for a budget. I tried to put on a R $ coin mask, but stopped calculating. It would also need a general grand field, but I do not even know where to start. (I'm improving a bit in Jquery, but I'm turning to PHP.) Certainly what I've done so far will not be legal ...) Here's what I did:
function updateTotal_5744() {
var total_5744 = 0;
var list_5744 = document.getElementsByClassName("input[5744]");
var values = [];
for (var i = 0; i < list_5744.length; ++i) {
values.push(parseFloat(list_5744[i].value));
}
/****** Total ******/
total_5744 = values.reduce(function(previousValue, currentValue, index, array) {
return previousValue * currentValue;
});
if (isNaN(parseFloat(total_5744))) {
document.getElementById("valor_total[5744]").value = 0;
} else {
document.getElementById("valor_total[5744]").value = total_5744;
}
/****** Total ******/
}
function updateTotal_5745() {
var total_5745 = 0;
var list_5745 = document.getElementsByClassName("input[5745]");
var values = [];
for (var i = 0; i < list_5745.length; ++i) {
values.push(parseFloat(list_5745[i].value));
}
/****** Total ******/
total_5745 = values.reduce(function(previousValue, currentValue, index, array) {
return previousValue * currentValue;
});
if (isNaN(parseFloat(total_5745))) {
document.getElementById("valor_total[5745]").value = 0;
} else {
document.getElementById("valor_total[5745]").value = total_5745;
}
/****** Total ******/
}
function updateTotal_5746() {
var total_5746 = 0;
var list_5746 = document.getElementsByClassName("input[5746]");
var values = [];
for (var i = 0; i < list_5746.length; ++i) {
values.push(parseFloat(list_5746[i].value));
}
/****** Total ******/
total_5746 = values.reduce(function(previousValue, currentValue, index, array) {
return previousValue * currentValue;
});
if (isNaN(parseFloat(total_5746))) {
document.getElementById("valor_total[5746]").value = 0;
} else {
document.getElementById("valor_total[5746]").value = total_5746;
}
/****** Total ******/
}
function updateTotal_5747() {
var total_5747 = 0;
var list_5747 = document.getElementsByClassName("input[5747]");
var values = [];
for (var i = 0; i < list_5747.length; ++i) {
values.push(parseFloat(list_5747[i].value));
}
/****** Total ******/
total_5747 = values.reduce(function(previousValue, currentValue, index, array) {
return previousValue * currentValue;
});
if (isNaN(parseFloat(total_5747))) {
document.getElementById("valor_total[5747]").value = 0;
} else {
document.getElementById("valor_total[5747]").value = total_5747;
}
/****** Total ******/
}
function updateTotal_5748() {
var total_5748 = 0;
var list_5748 = document.getElementsByClassName("input[5748]");
var values = [];
for (var i = 0; i < list_5748.length; ++i) {
values.push(parseFloat(list_5748[i].value));
}
/****** Total ******/
total_5748 = values.reduce(function(previousValue, currentValue, index, array) {
return previousValue * currentValue;
});
if (isNaN(parseFloat(total_5748))) {
document.getElementById("valor_total[5748]").value = 0;
} else {
document.getElementById("valor_total[5748]").value = total_5748;
}
/****** Total ******/
}
function updateTotal_5749() {
var total_5749 = 0;
var list_5749 = document.getElementsByClassName("input[5749]");
var values = [];
for (var i = 0; i < list_5749.length; ++i) {
values.push(parseFloat(list_5749[i].value));
}
/****** Total ******/
total_5749 = values.reduce(function(previousValue, currentValue, index, array) {
return previousValue * currentValue;
});
if (isNaN(parseFloat(total_5749))) {
document.getElementById("valor_total[5749]").value = 0;
} else {
document.getElementById("valor_total[5749]").value = total_5749;
}
/****** Total ******/
}
function updateTotal_5750() {
var total_5750 = 0;
var list_5750 = document.getElementsByClassName("input[5750]");
var values = [];
for (var i = 0; i < list_5750.length; ++i) {
values.push(parseFloat(list_5750[i].value));
}
/****** Total ******/
total_5750 = values.reduce(function(previousValue, currentValue, index, array) {
return previousValue * currentValue;
});
if (isNaN(parseFloat(total_5750))) {
document.getElementById("valor_total[5750]").value = 0;
} else {
document.getElementById("valor_total[5750]").value = total_5750;
}
/****** Total ******/
}
<script type="text/javascript" src="https://blackrockdigital.github.io/startbootstrap-sb-admin-2/vendor/jquery/jquery.min.js"></script><divclass="form-group col-md-12">
<div class="linha_topo_orc">
<div class="row">
<div class="col-md-12" style="background-color: #0C3052; font-family: 'museo500'; color: #FFFFFF; padding-top: 10px; margin-bottom: 20px;">
<div class="col-md-2">
<p class="exp">Imagem</p>
</div>
<div class="col-md-2">
<p class="exp">Espécie</p>
</div>
<div class="col-md-2">
<p class="exp">Quantidade</p>
</div>
<div class="col-md-2">
<p class="exp_right">Tamanho</p>
</div>
<div class="col-md-2">
<p class="exp_right">Valor Unitário</p>
</div>
<div class="col-md-2">
<p class="exp_right">Valor Total</p>
</div>
</div>
</div>
</div>
<div class="linha_orc">
<div class="row">
<input name="id_item_up_orc[5744]" id="id_item_up_orc[5744]" type="checkbox" value="5744" checked style="display: none" />
<div class="col-md-2">
<img src='' style="width: 70%">
</div>
<div class="col-md-2" style="margin-top: 6px;">
Cachara
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5744] form-control' value="500" onchange='updateTotal_5744();' disabled>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" value="" name="tamanho[5744]" id="tamanho[5744]" class="form-control">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5744] form-control money' name="valor[5744]" id="valor[5744" value="" onchange='updateTotal_5744();'>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control money" name="valor_total[5744]" id="valor_total[5744]" value="">
</div>
</div>
</div>
</div>
<div class="linha_orc">
<div class="row">
<input name="id_item_up_orc[5745]" id="id_item_up_orc[5745]" type="checkbox" value="5745" checked style="display: none" />
<div class="col-md-2">
<img src='' style="width: 70%">
</div>
<div class="col-md-2" style="margin-top: 6px;">
Dourado
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5745] form-control' value="500" onchange='updateTotal_5745();' disabled>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" value="" name="tamanho[5745]" id="tamanho[5745]" class="form-control">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5745] form-control money' name="valor[5745]" id="valor[5745" value="" onchange='updateTotal_5745();'>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control money" name="valor_total[5745]" id="valor_total[5745]" value="">
</div>
</div>
</div>
</div>
<div class="linha_orc">
<div class="row">
<input name="id_item_up_orc[5746]" id="id_item_up_orc[5746]" type="checkbox" value="5746" checked style="display: none" />
<div class="col-md-2">
<img src='' style="width: 70%">
</div>
<div class="col-md-2" style="margin-top: 6px;">
Mandi
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5746] form-control' value="500" onchange='updateTotal_5746();' disabled>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" value="" name="tamanho[5746]" id="tamanho[5746]" class="form-control">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5746] form-control money' name="valor[5746]" id="valor[5746" value="" onchange='updateTotal_5746();'>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control money" name="valor_total[5746]" id="valor_total[5746]" value="">
</div>
</div>
</div>
</div>
<div class="linha_orc">
<div class="row">
<input name="id_item_up_orc[5747]" id="id_item_up_orc[5747]" type="checkbox" value="5747" checked style="display: none" />
<div class="col-md-2">
<img src='' style="width: 70%">
</div>
<div class="col-md-2" style="margin-top: 6px;">
Pacu
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5747] form-control' value="500" onchange='updateTotal_5747();' disabled>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" value="" name="tamanho[5747]" id="tamanho[5747]" class="form-control">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5747] form-control money' name="valor[5747]" id="valor[5747" value="" onchange='updateTotal_5747();'>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control money" name="valor_total[5747]" id="valor_total[5747]" value="">
</div>
</div>
</div>
</div>
<div class="linha_orc">
<div class="row">
<input name="id_item_up_orc[5748]" id="id_item_up_orc[5748]" type="checkbox" value="5748" checked style="display: none" />
<div class="col-md-2">
<img src='' style="width: 70%">
</div>
<div class="col-md-2" style="margin-top: 6px;">
Piapara
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5748] form-control' value="1000" onchange='updateTotal_5748();' disabled>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" value="" name="tamanho[5748]" id="tamanho[5748]" class="form-control">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5748] form-control money' name="valor[5748]" id="valor[5748" value="" onchange='updateTotal_5748();'>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control money" name="valor_total[5748]" id="valor_total[5748]" value="">
</div>
</div>
</div>
</div>
<div class="linha_orc">
<div class="row">
<input name="id_item_up_orc[5749]" id="id_item_up_orc[5749]" type="checkbox" value="5749" checked style="display: none" />
<div class='' style="width: 70%">
</div>
<div class="col-md-2" style="margin-top: 6px;">
Tambaqui
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5749] form-control' value="1000" onchange='updateTotal_5749();' disabled>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" value="" name="tamanho[5749]" id="tamanho[5749]" class="form-control">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5749] form-control money' name="valor[5749]" id="valor[5749" value="" onchange='updateTotal_5749();'>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control money" name="valor_total[5749]" id="valor_total[5749]" value="">
</div>
</div>
</div>
</div>
<div class="linha_orc">
<div class="row">
<input name="id_item_up_orc[5750]" id="id_item_up_orc[5750]" type="checkbox" value="5750" checked style="display: none" />
<div class="col-md-2">
<img src='' style="width: 70%">
</div>
<div class="col-md-2" style="margin-top: 6px;">
Tucunaré
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5750] form-control' value="500" onchange='updateTotal_5750();' disabled>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" value="" name="tamanho[5750]" id="tamanho[5750]" class="form-control">
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class='input[5750] form-control money' name="valor[5750]" id="valor[5750" value="" onchange='updateTotal_5750();'>
</div>
</div>
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control money" name="valor_total[5750]" id="valor_total[5750]" value="">
</div>
</div>
</div>
</div>
</div>