I am stuck in a problem, I need to take the result of the amount and saving variables and send them to the inputs that are hidden at the same time that they are printed on the screen, to send them through a form. I have searched for information about it but I can't find it. I greatly appreciate any help. Thanks.
// Compara los valores, metros cuadrados y total
document.form.onchange = function(){
var metrosValor = document.getElementById("metros").value / 10; // Primer valor
var totalValor = document.getElementById("total").value; // Segundo valor
if(parseInt(metrosValor)>parseInt(totalValor)){
document.form.comparativa1.value='' + metrosValor + ''; // Primer valor es mas grande que el segundo
}else if(parseInt(metrosValor)<parseInt(totalValor)){
document.form.comparativa1.value='' + metrosValor + ''; // Primer valor es mas pequeño que el segundo
}else{
document.form.comparativa1.value=''; // Si son iguales no muestra resultado.
}
}
// Muestra resultado del ahorro, antes de enviar formulario
function resultadoAhorro(){
var comparaMetrosTotal=document.form.comparativa1.value;
var importe=document.form.comparativa1.value*950;
var ahorro=document.form.comparativa1.value*3.8*0.95;
var correo=document.form.email.value;
//var total=document.form.total.value;
//var kWp=document.form.totalkWp.value;
document.getElementById('mensajeTotalAhorro').innerHTML='<h3 style="font-size:18px"><img src="img/potencia.png">Potencia ofertada: ' + comparaMetrosTotal + ' kWp</h3> <h3 style="font-size:18px"><img src="img/importe.png">Importe de la instalación: ' + importe + ' €</h3> <h3 style="font-size:18px"><img src="img/ahorro.png">Ahorros a futuro: ' + ahorro + ' €</h3> <p>El plazo de amortización para este tipo de instalaciones está entre 5 y 7 años, con una vida útil superior a 25 años. Más información en tu correo ' + correo + '</p><br>';
}
<input type="hidden" class="form-control" id="importe" name="Importeinstalación" readonly="readonly">
<input type="hidden" class="form-control" id="ahorro" name="Ahorroaproximado" readonly="readonly">
After you do this:
Put the following:
After obtaining the text field, what is done is to modify its value property, which is nothing more than setting the value you want.
If your form is called "form" that is, it has the name attribute with that value, you could also do it this way:
You are accessing the components through their name attribute, name of the form form , access it: document.form , name of the text field corresponding to the installation amount , access it: document.form.InstallationAmount
Hope this can help you :)