0
Good morning to all
I have a function to multiply qnt * total, but it only loads after clicking the field vrunitario
. I wish that when opening the page she would calculate, I don’t know where I went wrong here in the code.
$("#tbodyCotacao").on("blur keyup load",'input[id^="pqnt"],input[id^="vrunit01"],input[id^="vrunit02"],input[id^="vrunit03"]', function (event) {
multiplicar($(this).closest("tr"));});
function multiplicar(row) {
var vlund01 = row.find('input[id^="vrunit01"]').val();
//retira separadores de milhar ponto
vlund01 = vlund01.split(".").join("");
//substitui separador decimal virgula por ponto
vlund01=vlund01.replace(",", ".");
vlund01 = +vlund01;
var qnd = +row.find('input[id^="pqnt"]').val();
//total para uso nos calculos
//2 casas decimais
var total01 = (vlund01 * qnd).toFixed(2);
row.find('input[id^="subtotal01"]').val(total01);
//totalS para uso na apresentação substitui separador decimal ponto por virgula
totalS01=total01.replace(".", ",");
//a regex abaixo coloca um ponto a esquerda de cada grupo de 3 digitos desde que não seja no inicio do numero
row.find('input[id^="subtotal01T"]').val((totalS01).replace(/\B(?=(\d{3})+(?!\d))/g, "."));
}
PROVISIONAL MEASURE People I made a provision measure, to appear and improved but I would like that appeared in the page loading.
$(document).ready(function () {
$("#tbodyCotacao").on("change keyup keydown paste propertychange bind mouseover",'input[id^="pqnt"],input[id^="vrunit01"],input[id^="vrunit02"],input[id^="vrunit03"]', function (event) {
multiplicar($(this).closest("tr"));
});
function multiplicar(row) {
var vlund01 = row.find('input[id^="vrunit01"]').val();
//retira separadores de milhar ponto
vlund01 = vlund01.split(".").join("");
//substitui separador decimal virgula por ponto
vlund01=vlund01.replace(",", ".");
vlund01 = +vlund01;
var qnd = +row.find('input[id^="pqnt"]').val();
//total para uso nos calculos
//2 casas decimais
var total01 = (vlund01 * qnd).toFixed(2);
row.find('input[id^="subtotal01"]').val(total01);
//totalS para uso na apresentação substitui separador decimal ponto por virgula
totalS01=total01.replace(".", ",");
//a regex abaixo coloca um ponto a esquerda de cada grupo de 3 digitos desde que não seja no inicio do numero
row.find('input[id^="subtotal01T"]').val((totalS01).replace(/\B(?=(\d{3})+(?!\d))/g, "."));}
In jQuery you can put your code inside the function
ready
in thedocument
which will be executed when the document is loaded. Example:$(document).ready(function(){ //seu código });
or just$(function(){ //seu código });
– Laércio Lopes
I don’t understand this part:
$(this).closest("tr")
. It’s all in onetr
? By the image I’m seeing several lines and not just one. Or is it all within onetd
in one line?– Sam
That’s because the event
load
will not work with div, so it would be necessary to create it separately and call the functionmultiplicar(row)
.– Sam
Why are you wearing
^=
on the selectors? Are several of these forms on the screen at the same time? That onevrunitario
is unique? Whatid
of it? To make the eventload
work you need to know what to send in the variablerow
of function.– Sam
Would have to do
$(window).on("load", function(){ multiplicar(row); });
... the problem is: what to send in thisrow
since you don’t have the$(this)
of the other eventsblur
andkeyup
that you created?– Sam
Lercio - I tried to do it didn’t work.
– frodrigues
Sam - It is a dynamic table, insert and remove lines to be saved in the bank. To enter worked perfectly, to show that this is giving this inconvenience. The load event was testing to make it load the calculation. I already made the screen to insert, this screen would be to edit, then you have to load what is saved in the bank and have option to insert the remove lines.
– frodrigues