Skip to content

Instantly share code, notes, and snippets.

@dantetesta
Created March 8, 2023 03:17
Show Gist options
  • Save dantetesta/ab71c4f9a104a1a594ab73bfa8c81796 to your computer and use it in GitHub Desktop.
Save dantetesta/ab71c4f9a104a1a594ab73bfa8c81796 to your computer and use it in GitHub Desktop.
<style>
input[name='mensalidade']{
display: none;
}
#mensagem{
display: none;
color: white;
background:green;
font-size: 22px;
font-weight: bold;
border: 2px solid darkgreen;
padding: 20px;
border-radius: 8px;
width: 350px;
margin-bottom: 10px;
}
a#fechar{
display: none;
font-size: 15px;
color: red;
padding: 15px;
border: 1px solid red;
background: white;
border-radius: 8px;
width: 350px;
text-align: center;
}
</style>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-maskmoney/3.0.2/jquery.maskMoney.min.js" integrity="sha512-Rdk63VC+1UYzGSgd3u2iadi0joUrcwX0IWp2rTh6KXFoAmgOjRS99Vynz1lJPT8dLjvo6JZOqpAHJyfCEZ5KoA==" crossorigin="anonymous" referrerpolicy="no-referrer"></script>
<script>
jQuery(document).ready(function(){
jQuery("input[name='valor']").maskMoney({prefix:'R$ ', allowNegative: true, thousands:'.', decimal:',', affixesStay: false});
function getValue(value) {
var dados = [
[1, 15000, 139.15],
[15001, 20000, 153.20],
[20001, 25000, 179.25],
[25001, 30000, 195.30],
[30001, 35000, 212.35],
[35001, 40000, 229.40],
[40001, 45000, 246.45],
[45001, 50000, 263.50],
[50001, 55000, 280.55],
[55001, 60000, 297.60],
[60001, 65000, 314.65],
[65001, 70000, 331.70],
[70001, 75000, 348.75],
[75001, 80000, 365.80],
[80001, 85000, 382.85],
[85001, 90000, 399.90],
[90001, 95000, 416.95],
[95001, 100000, 433.00],
[100001, 110000, 450.11],
[110001, 120000, 467.12]
];
for (var i = 0; i < dados.length; i++) {
if (value >= dados[i][0] && value <= dados[i][1]) {
return dados[i][2];
}
}
}
jQuery('input[name="valor"]').keyup(function(){
var valor = jQuery(this).val();
valor = valor.replace(/[^0-9]/g, '');
valor = valor.substring(0, valor.length - 2);
var valor_int = parseInt(valor.replace(/[^0-9]/g, ''));
jQuery("input[name='mensalidade']").val(getValue(valor_int).toLocaleString('pt-BR', { style: 'currency', currency: 'BRL' }));
});
jQuery("#fechar").click(function(){
jQuery("#mensagem, #fechar").fadeOut('fast');
});
jQuery(".wpcf7-form").submit(function(e){
e.preventDefault();
var nome = jQuery("input[name='nome']").val();
var telefone = jQuery("input[name='telefone']").val();
var possui_veiculo = jQuery("input[name='possui-veiculo']").val();
var valor = jQuery("input[name='valor']").val();
var mensalidade = jQuery("input[name='mensalidade']").val();
if(nome == "" || telefone == "" || possui_veiculo == "" || valor == "" || mensalidade == ""){
alert("Preencha todos os campos!");
}else{
jQuery("#mensagem").html(nome+"<br> O Valor da Mensalidade é:<br> "+mensalidade).css('display','block');
jQuery("#fechar").css('display','block');
}
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment