2
Well, what I intended was to replace the javascript word "Nan" with 0.
I’ve searched some topics here on stackoverflow but none helped me.
What would be the code to make this change?
Thank you.
@EDIT:
I tried to do it this way, but now the values are giving me Undefined:
I’m sorry if I’m really making a mistake, but I’m still novice at js and have the same "reasoning" as php.
<!DOCTYPE HTML>
<html>
<head>
</head>
<script>
function calcular(){
var valor1 = parseInt(document.getElementById('bikemountain').value);
var valor2 = parseInt(document.getElementById('bikesenhora').value);
var valor3 = parseInt(document.getElementById('bikecrianca').value);
if(valor1 == null){
var totalvalores = valor2 + valor3;
}
if(valor2 == null){
var totalvalores = valor1 + valor3;
}
if(valor3 == null){
var totalvalores = valor1 + valor2;
}
document.getElementById('precoapagar').innerHTML = totalvalores;
}
setInterval("calcular()",100);
</script>
<form action="verifica1.php" method="post">
<h3><b>Informações Pessoais</b></h3>
<br>
Nome: <input type="text" name="nome" required>
<br>
<br>
Tipo de Documento de Identifcação:
<select>
<option value="cartaocidadao">Cartão de Cidadão</option>
<option value="bilheteidentidade">Bilhete de Identidade</option>
<option value="passaporte">Passaporte</option>
<option value="cartaconducao">Carta de Condução</option>
</select>
<br>
<br>
Telemóvel: <input type="telemovel" required>
<br>
<br>
<b><h3>Levantamento</h3></b>
Número de Bicicletas tipo Mountain Bike: <input type="text" name="bikemountain" id="bikemountain">
<br>
<br>
Número de Bicicletas de Senhora: <input type="text" name="bikesenhora" id="bikesenhora">
<br>
<br>
Número de Bicicletas de Criança: <input type="text" name="bikecrianca" id="bikecrianca">
<br>
<br>
Dia de Levantamento:
<input type="date" name="dialevantamento" required>
<br>
<br>
Hora de Levantamento
<input type="time" name="horalevantamento" required>
<br>
<br>
Tempo Desejado:
<input type='number' name="tempodesejado" onblur="calcular()" id="tempodesejado" step=1 required>
<select id="tipo" name="tipo">
<option value="horas">Horas</option>
<option value="dias">Dias</option>
</select>
<br>
<br>
<br>
Preço a Pagar: <span id="precoapagar">0</span>€
<br>
<br>
<input type="submit" value="Prosseguir!">
</form>
</html>
What is your function ?
– user46523
At what point you want to take the test?
– Diego
I want to do the type, ie if the input 1 has nothing, the total variable values is only the value 2+ Valor3 ie only calculates the other 2, and the same reasoning with the other all.
– Gonçalo