I am making a system for a virtual store, from which the user will have the value of the package. For example: R $ 12.000,00, however he will have the option to choose the travel insurance through the code below:
Seguro Viagem?<br>
<input type='radio' name='Seguro' value='Sim'> Sim
<input type='radio' name='Seguro' value='Não'> Não
How to select Yes, the travel insurance value be summed with the value of the package and change the final value? Ex.:
(without insurance) Value: R $ 12,000.00
When you click Yes, change to:
(with insurance) Insurance: R $ 500.00 Value: R $ 12,500.00
I tried using the code below but it is not working:
<script language="Javascript">
function soma(){
valorSeguro = 500.00;
valorPacote = 1200.00;
e = valorSeguro + valorPacote;
if(e.toFixed(2) == "NaN"){
document.getElementById("total").innerHTML = "USD 0.00";
}else{
document.getElementById("total").innerHTML = "USD "+e.toFixed(2)+"";
}
}
</script>
Seguro Viagem?<br>
<input type='radio' name='Seguro' onchange="soma()" value='Sim'> Sim
<input type='radio' name='Seguro' value='Não'> Não<br><br>
<div id="total" style="font-family:Arial; font-size:16px">USD 12.000,00</div>
Thank you!