2
I have a table with two fields: "Product Value" and "Sale Price". Another field to define a calculation for the "Sale Price". The function only works for the first row of the table. I would like to know how to make the calculation to be applied on all lines in the sales price field.
function fctprecovenda(form) {
var valprod = parseFloat(form1.valprod.value);
var percentual = parseFloat(form1.percentual.value);
var precovenda = (valprod + percentual * valprod / 100);
form1.prcvenda.value = precovenda.toFixed(2);
}
<form method="post" id="form1">
<label >Definer valor %</label>
<input type="text" name="percentual" value="" onblur="fctprecovenda(form1)">
<table id ="tabvenda" nome ="tabvenda">
<tr>
<th>Valor do Produto<th>
<th>Preço de venda<th>
</tr>
<tr>
<td><input type="text" name="valprod" value="50"></td>
<td><input type="text" name="prcvenda" value=""></td>
</tr>
<tr>
<td><input type="text" name="valprod" value="100"></td>
<td><input type="text" name="prcvenda" value=""></td>
</tr>
</table>
</form>
Vmartins, thank you very much, worked exactly as needed. I only changed the formula I calculated to var precovenda = Number(valprod) + ( Number(valprod) * Number(percentage) / 100);
– GiaN
vmartins, a question has arisen. How do I calculate the function when clicking a button?
– GiaN
Do the calculation on all rows of the table? If so, just change the event (set by the first line of the JS): $(selector). on('click', Function() {
– vmartins
Little code and very functional, congratulations.
– Victor Matheus Mendes
Thanks again. The doubt is solved.
– GiaN