4
As the code shows with several textfield, I want to make visible only date, date and KM and from these 3 fill in the others that will be invisible, the amount to be paid will be displayed on an Alert when you click on simulate. The account is working, but I need to keep clicking on the textfield fields to be able to fill in, so that the calculation is blank.
function funcao1()
{
var form3 = document.getElementById('simulador');
var valorreal = document.getElementById('valorreal');
form3.addEventListener('submit', function(e) {
// alerta o valor do campo
alert("O valor total a ser pago será de: " + "R$" + valorreal.value);
// impede o envio do form
e.preventDefault();
});
}
function calcula_valor(){
document.form3.valortotal.value = document.form3.KM.value * document.form3.valorKM.value;
//document.form3.valortotal.value = ((document.form3.dataSaida.value - document.form3.dataEntrada.value) * document.form3.diaria.value) + (document.form3.KM.value * document.form3.ValorKM.value);
}
function difDias(){
var dataSaida = new Date(document.getElementById("dataSaida").value);
var dataEntrada = new Date(document.getElementById("dataEntrada").value);
return parseInt((dataSaida - dataEntrada) / (24 * 3600 * 1000));
}
function chamar(){
document.getElementById("ndias").value = isNaN(difDias()) ? "" : difDias();
}
function calcula_aluguel(){
document.form3.valoraluguel.value = document.form3.ndias.value * document.form3.diaria.value;
}
function calculo_total(){
document.form3.valorreal.value = (document.form3.valoraluguel.value*1) + (document.form3.valortotal.value*1);
}
<section class="bloco3">
<div id="title3">
<p id="title3">Simulador</p>
</div>
<div id="simulador">
<div id="form3">
<form class="bloco3" name="form3" action="" method="post">
<input type="date" id="dataEntrada" name="dataEntrada" placeholder="dataEntrada" onchange="chamar()">
<input type="date" id="dataSaida" name="dataSaida" placeholder="dataSaida" onchange="chamar()">
<input type="text" id="ndias" name="ndias" value="" placeholder="nº dias">
<input type="hidden" id="diaria" name="diaria" value="50" required="" placeholder="Diaria">
<input type="text" id="valoraluguel" name="valoraluguel" value="" onclick="calcula_aluguel()" onkeyup="calcula_aluguel()" placeholder="valor da diaria">
<input type="hidden" id="valorKM" name="valorKM" value="2" placeholder="valorKM">
<input type="text" id="KM" name="KM" value="" onclick="calcula_valor()" onkeyup="calcula_valor()" placeholder="digite o KM percorrido">
<input type="text" id="valortotal" name="valortotal" value="" placeholder="valor total do KM percorrido">
<input type="text" id="valorreal" name="valorreal" value="" onclick="calculo_total()" onkeyup="calculo_total()" placeholder="valor total a ser pago">
<input type="submit" onclick="return funcao1()" onkeyup="funcao1()" value="Simular" />
</form>
</div>
</div>
</section>
@dvd , that competitive! I will run behind and improve this code!!
– user60252
@Leocaracciolo turned dispute that here hahahaha
– Zorro Cerveró
Boy, we’ll study the code, we’ll understand more and more and then we’ll improve it.
– user60252
I like what’s perfect!!
– user60252
@Leocaracciolo oloco, I look forward to perfection then hahahaha. Thank you for all the help you have given me and are giving me
– Zorro Cerveró
but I think I’ve reached the goal, test my answer and tell me if something isn’t right.
– user60252
@Leocaracciolo all right tmb, now I have two code options to use hahahaha
– Zorro Cerveró