0
I am trying to get data coming from the database, for each input, to make calculations among themselves in real time and give me a final value before registering the form.
I have a table and on this table, a part to tr
of it is added dynamically. there is a select that, when selecting an item, pulls the value of that item into the database and shows the value, allowing that when choosing the quantity the value is changed, that part is working.
What I could not do is take the result of the total value of the items, and decrease from another field that comes from the database with royallties value for example. the final result appears as NaN
as if something in the code wasn’t defined as a number could help me?
var value = elemento.parentElement.parentElement.querySelector('td > input#valor_unitario').value;
var valor = parseFloat(value.replace("R$","").replace(",","."));
var total = parseInt(qnt) * parseFloat(valor);
cell_total.value = "R$ " + total.toFixed(2);
var total = parseFloat(value.replace("R$","").replace(",","."));
var royallties = parseFloat(value.replace(",",".").replace("","%"));
var valorroyallties = parseFloat(total) - ((parseFloat(total)* parseFloat(royallties))/100);
var valorfinal = parseFloat(total) - parseFloat(valorroyallties);
cell_valorfinal.value = "R$ " + valorfinal.toFixed(2);
in this case the value is not entered it comes from the database... the user only uses a select to choose an item and all values come from the database related that item the only field that the user interact
– lgbruno