3
Script Membership Value
function mascara(o,f){
v_obj=o
v_fun=f
setTimeout("execmascara()",1)
}
function execmascara(){
v_obj.value=v_fun(v_obj.value)
}
function mreais(v){
v=v.replace(/\D/g,"") //Remove tudo o que não é dígito
v=v.replace(/(\d{2})$/,",$1") //Coloca a virgula
v=v.replace(/(\d+)(\d{3},\d{2})$/g,"$1.$2") //Coloca o primeiro ponto
return v
}
Input of Accession Value:
<input type="text" id="txt1" name="adesao" class="form-control calcular" placeholder="R$" onkeypress="mascara(this,mreais)" onkeyup="calcular()">
Script Total Value
function calcular() {
var soma = $('.calcular').get().reduce(function(soma, el) {
return (parseFloat(el.value.replace(/\./g, "").replace(",", "."), 10) || 0) + soma;
}, 0);
document.getElementById('result').value = soma;
}
Input Total Value
<input type="text" class="form-control" name="total" id="result" readonly>