After several troubleshooting steps, I'm at the bottom of a search form I'm putting together. To conclude, there are two problems: in the "Monthly Verba" column, the "toLocaleString" does not work. The result of the calculation of 90.00 x 2 gets 180, instead of getting $ 180.00 (strange is that in total it worked). In the "Daily cash" column, if I put the "maskMoney" mask (which is on Facebook visit site), the calculation is "NaN". What would be wrong?
I've edited the code with the fixes here. The fields solved the problem, but the three totals stopped adding up. If on the "Google Adwords" line I put $ 1,250.00 x 2, Nan now returns. If I put $ 250.00 x 3, it returns $ 500.00.
$(".real").maskMoney({
prefix: 'R$ ',
thousands: '.',
decimal: ',',
affixesStay: true
});
$(document).ready(function() {
var formato = {
minimumFractionDigits: 2,
style: 'currency',
currency: 'BRL'
}
/****** Cálculos Google Adwords ******/
$('#vd_ga').on('blur', function() {
var vd_ga = $('#vd_ga').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var pvm_ga = $('#pvm_ga').val();
//$('#vm_ga').val(vd_ga * pvm_ga);
$("#vm_ga").val((vd_ga * pvm_ga).toLocaleString('pt-BR', formato));
$('#eam_ga').val(vd_ga * pvm_ga);
});
$('#pvm_ga').on('blur', function() {
var vd_ga = $('#vd_ga').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var pvm_ga = $('#pvm_ga').val();
$('#vm_ga').val((vd_ga * pvm_ga).toLocaleString('pt-BR', formato));
$('#eam_ga').val(vd_ga * pvm_ga);
});
/****** Cálculos Google Adwords ******/
/****** Cálculos Facebook visita site ******/
$('#vd_fvs').on('blur', function() {
//var vd_fvs = $('#vd_fvs').val().replace(',', '.');
var vd_fvs = $('#vd_fvs').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var pvm_fvs = $('#pvm_fvs').val();
$('#vm_fvs').val((vd_fvs * pvm_fvs).toLocaleString('pt-BR', formato));
$('#eam_fvs').val(vd_fvs * pvm_fvs);
});
$('#pvm_fvs').on('blur', function() {
//var vd_fvs = $('#vd_fvs').val().replace(',', '.');
var vd_fvs = $('#vd_fvs').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var pvm_fvs = $('#pvm_fvs').val();
$('#vm_fvs').val((vd_fvs * pvm_fvs).toLocaleString('pt-BR', formato));
$('#eam_fvs').val(vd_fvs * pvm_fvs);
});
/****** Cálculos Facebook visita site ******/
/****** Cálculos Facebook curtida na página ******/
$('#vd_fcp').on('blur', function() {
var vd_fcp = $('#vd_fcp').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var pvm_fcp = $('#pvm_fcp').val();
$('#vm_fcp').val((vd_fcp * pvm_fcp).toLocaleString('pt-BR', formato));
$('#eam_fcp').val(vd_fcp * pvm_fcp);
});
$('#pvm_fcp').on('blur', function() {
var vd_fcp = $('#vd_fcp').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var pvm_fcp = $('#pvm_fcp').val();
$('#vm_fcp').val((vd_fcp * pvm_fcp).toLocaleString('pt-BR', formato));
$('#eam_fcp').val(vd_fcp * pvm_fcp);
});
/****** Cálculos Facebook curtida na página ******/
/****** Cálculos Instagram seguidores ******/
$('#vd_is').on('blur', function() {
var vd_is = $('#vd_is').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var pvm_is = $('#pvm_is').val();
$('#vm_is').val((vd_is * pvm_is).toLocaleString('pt-BR', formato));
$('#eam_is').val(vd_is * pvm_is);
});
$('#pvm_is').on('blur', function() {
var vd_is = $('#vd_is').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var pvm_is = $('#pvm_is').val();
$('#vm_is').val((vd_is * pvm_is).toLocaleString('pt-BR', formato));
$('#eam_is').val(vd_is * pvm_is);
});
/****** Cálculos Instagram seguidores ******/
/****** Cálculo total 1 ******/
$('#vd_ga, #pvm_ga, #vd_fvs, #pvm_fvs, #vd_fcp, #pvm_fcp, #vd_is, #pvm_is').on('input', function() {
var vm_ga = parseFloat($("#vm_ga").val().replace(/[^\d.,]/g, "").replace('.', '').replace(',', '.'));
var vm_fvs = parseFloat($("#vm_fvs").val().replace(/[^\d.,]/g, "").replace('.', '').replace(',', '.'));
var vm_fcp = parseFloat($("#vm_fcp").val().replace(/[^\d.,]/g, "").replace('.', '').replace(',', '.'));
var vm_is = parseFloat($("#vm_is").val().replace(/[^\d.,]/g, "").replace('.', '').replace(',', '.'));
var total_1 = vm_ga + vm_fvs + vm_fcp + vm_is;
//if(!isNaN(total_1)) $('#total_1').val(total_1);
//if(!isNaN(total_1)) $("#total_1").val(total_1.toLocaleString('pt-BR', formato));
if (!isNaN(total_1)) $('#total_1').val((total_1).toLocaleString('pt-BR', formato));
});
/****** Cálculo total 1 ******/
/*********************************************************************************************/
/****** Cálculos Facebook impulsionamento de posts ******/
$('#vd_fip').on('blur', function() {
var vd_fip = $('#vd_fip').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var qpm_fip = $('#qpm_fip').val();
$('#vm_fip').val((vd_fip * qpm_fip).toLocaleString('pt-BR', formato));
$('#eap_fip').val(vd_fip * 75);
var eap_fip = $('#eap_fip').val();
$('#eatpm_fip').val(qpm_fip * eap_fip);
});
$('#qpm_fip').on('blur', function() {
var vd_fip = $('#vd_fip').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var qpm_fip = $('#qpm_fip').val();
$('#vm_fip').val((vd_fip * qpm_fip).toLocaleString('pt-BR', formato));
$('#eap_fip').val(vd_fip * 75);
var eap_fip = $('#eap_fip').val();
$('#eatpm_fip').val(qpm_fip * eap_fip);
});
/****** Cálculos Facebook impulsionamento de posts ******/
/****** Cálculos Instagram impulsionamento de posts ******/
$('#vd_iip').on('blur', function() {
var vd_iip = $('#vd_iip').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var qpm_iip = $('#qpm_iip').val();
$('#vm_iip').val((vd_iip * qpm_iip).toLocaleString('pt-BR', formato));
$('#eap_iip').val(vd_iip * 75);
var eap_iip = $('#eap_iip').val();
$('#eatpm_iip').val(qpm_iip * eap_iip);
});
$('#qpm_iip').on('blur', function() {
var vd_iip = $('#vd_iip').val().replace("R$ ", "").replace('.', '').replace(',', '.');
var qpm_iip = $('#qpm_iip').val();
$('#vm_iip').val((vd_iip * qpm_iip).toLocaleString('pt-BR', formato));
$('#eap_iip').val(vd_iip * 75);
var eap_iip = $('#eap_iip').val();
$('#eatpm_iip').val(qpm_iip * eap_iip);
});
/****** Cálculos Instagram impulsionamento de posts ******/
/****** Cálculo total 2 ******/
$('#vd_fip, #qpm_fip, #vd_iip, #qpm_iip').on('input', function() {
var vm_fip = parseFloat($("#vm_fip").val().replace(/[^\d.,]/g, "").replace('.', '').replace(',', '.'));
var vm_iip = parseFloat($("#vm_iip").val().replace(/[^\d.,]/g, "").replace('.', '').replace(',', '.'));
var total_2 = vm_fip + vm_iip;
//if(!isNaN(total_2)) $('#total_2').val(total_2);
//if(!isNaN(total_2)) $("#total_2").val(total_2.toLocaleString('pt-BR', formato));
if (!isNaN(total_2)) $('#total_2').val((total_2).toLocaleString('pt-BR', formato));
});
/****** Cálculo total 2 ******/
/****** Cálculo totais ******/
$('#vd_ga, #pvm_ga, #vd_fvs, #pvm_fvs, #vd_fcp, #pvm_fcp, #vd_is, #pvm_is, #vd_fip, #qpm_fip, #vd_iip, #qpm_iip').on('input', function() {
var total_1 = parseFloat($("#total_1").val().replace(/[^\d.,]/g, "").replace('.', '').replace(',', '.'));
var total_2 = parseFloat($("#total_2").val().replace(/[^\d.,]/g, "").replace('.', '').replace(',', '.'));
var total_geral = total_1 + total_2;
//if(!isNaN(total_geral)) $('#total_geral').val(total_geral);
//if(!isNaN(total_geral)) $("#total_geral").val(total_geral.toLocaleString('pt-BR', formato));
if (!isNaN(total_geral)) $('#total_geral').val((total_geral).toLocaleString('pt-BR', formato));
});
/****** Cálculo totais ******/
});
<script src="https://www.agenciamove.com.br/briefing/js/jquery-2.1.3.min.js"></script><scripttype="text/javascript" src="https://plentz.github.io/jquery-maskmoney/javascripts/jquery.maskMoney.min.js"></script><divclass="row">
<div class="col-xs-12 col-sm-2 col-md-3 titulo_ferramenta">
Canais online
</div>
<div class="col-xs-12 col-sm-2 col-md-2 titulo_ferramenta">
Verba diária
</div>
<div class="col-xs-12 col-sm-2 col-md-2 titulo_ferramenta">
Período de vericulação mensal
</div>
<div class="col-xs-12 col-sm-2 col-md-2 titulo_ferramenta">
Verba mensal
</div>
<div class="col-xs-12 col-sm-2 col-md-3 titulo_ferramenta">
Estimativa de alcance mensal
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-3 col-md-3 canais_titulo">
Google Adwords
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vd_ga" id="vd_ga" class="real input_geral" type="text" />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="pvm_ga" id="pvm_ga" class="input_geral_2" type="text" /><span class="canais_titulo"> dias</span>
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vm_ga" id="vm_ga" class="real input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-3">
<input name="eam_ga" id="eam_ga" class="input_geral_2" type="text" readonly /><span class="canais_titulo"> Cliques</span>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-3 canais_titulo">
Facebook visita site
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vd_fvs" id="vd_fvs" class="real input_geral" type="text" />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="pvm_fvs" id="pvm_fvs" class="input_geral_2" type="text" /><span class="canais_titulo"> dias</span>
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vm_fvs" id="vm_fvs" class="real input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-3">
<input name="eam_fvs" id="eam_fvs" class="input_geral_2" type="text" readonly /><span class="canais_titulo"> Cliques</span>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-3 canais_titulo">
Facebook curtida na página
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vd_fcp" id="vd_fcp" class="real input_geral" type="text" />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="pvm_fcp" id="pvm_fcp" class="input_geral_2" type="text" /><span class="canais_titulo"> dias</span>
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vm_fcp" id="vm_fcp" class="real input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-3">
<input name="eam_fcp" id="eam_fcp" class="input_geral_2" type="text" readonly /><span class="canais_titulo"> Cliques</span>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-3 canais_titulo">
Instagram seguidores
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vd_is" id="vd_is" class="real input_geral" type="text" />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="pvm_is" id="pvm_is" class="input_geral_2" type="text" /><span class="canais_titulo"> dias</span>
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vm_is" id="vm_is" class="real input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-3">
<input name="eam_is" id="eam_is" class="input_geral_2" type="text" readonly /><span class="canais_titulo"> Cliques</span>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-3"></div>
<div class="col-xs-12 col-sm-4 col-md-4 canais_titulo text-right">
Valor total verba mês
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="total_1" id="total_1" class="real input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-3"></div>
</div>
<hr />
<div class="titulo_pag_ferramenta">Já na ferramenta de impulsionamentos, basta colocar o valor diário e a quantidade de posts que deseja estar postando mensalmente:</div>
<hr />
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-2 titulo_ferramenta">
Canais online
</div>
<div class="col-xs-12 col-sm-2 col-md-2 titulo_ferramenta">
Verba diária
</div>
<div class="col-xs-12 col-sm-2 col-md-2 titulo_ferramenta">
Quantidade de posts mês
</div>
<div class="col-xs-12 col-sm-2 col-md-2 titulo_ferramenta">
Verba mensal
</div>
<div class="col-xs-12 col-sm-2 col-md-2 titulo_ferramenta">
Estimativa de alcance por post
</div>
<div class="col-xs-12 col-sm-2 col-md-2 titulo_ferramenta">
Estimativa de alcance total de posts mês
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-2 canais_titulo">
Facebook impulsionamento de posts
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vd_fip" id="vd_fip" class="real input_geral" type="text" />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="qpm_fip" id="qpm_fip" class="input_geral" type="text" />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vm_fip" id="vm_fip" class="real input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="eap_fip" id="eap_fip" class="input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="eatpm_fip" id="eatpm_fip" class="input_geral" type="text" readonly />
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-2 canais_titulo">
Instagram impulsionamento de posts
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vd_iip" id="vd_iip" class="real input_geral" type="text" />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="qpm_iip" id="qpm_iip" class="input_geral" type="text" />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="vm_iip" id="vm_iip" class="real input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="eap_iip" id="eap_iip" class="input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="eatpm_iip" id="eatpm_iip" class="input_geral" type="text" readonly />
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-2">
</div>
<div class="col-xs-12 col-sm-4 col-md-4 canais_titulo text-right">
Valor total verba mês
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="total_2" id="total_2" class="real input_geral" type="text" readonly />
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
</div>
</div>
<hr />
<div class="row">
<div class="col-xs-12 col-sm-2 col-md-2">
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
</div>
<div class="col-xs-12 col-sm-4 col-md-4 canais_titulo text-right">
Geral
</div>
<div class="col-xs-12 col-sm-2 col-md-2">
<input name="total_geral" id="total_geral" class="real input_geral" type="text" readonly />
</div>
</div>