I'm trying to get data from the database, for each input, to make calculations with each other in real time and give me a final value before registering the form.
I have a table and in that table, a part of tr
is added dynamically. there is a select that, when selecting an item, pulls the value of that item in the database and shows the value, allowing the amount to be changed when choosing the quantity, this part is working.
What I could not do is get the result of the total value of the items, and decrease from another field that comes from the database with value of royallties for example. does the final result appear as NaN
as if something in the code was not set 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);