I have a problem with this code I try to perform an operation that subtracts it from the result of two inputs
is shown in another input
but being empty at the beginning I mark the error NaN only gives me the result when running again the script
function calcular() {
var n1 = parseInt(document.dosificacion.capacidad.value);
var n3 = parseInt(document.dosificacion.fijador.value);
var n5 = parseInt(document.dosificacion.dosificacion.value);
// alerta
if (isNaN(n1)) {
alert('Ingresa el capacidad');
} else {
document.dosificacion.esencia.value = (n1 * n5) / (100).toFixed();
var n2 = parseInt(document.dosificacion.esencia.value);
document.dosificacion.esencia.value += " g.";
document.dosificacion.fijador.value = (n1 * .08).toFixed() + " g.";
document.dosificacion.perfumol.value = (n1 - n2 - n3).toFixed() + " g.";
}
}
<form name="dosificacion">
<div>
<input class="capacidad" type="text" name="capacidad"><br>
</div>
<p></p>
<div>
<input class="esencia" type="text" name="esencia"><br>
</div>
<p></p>
<div>
<input class="perfumol" type="text" name="perfumol"><br>
</div>
<p></p>
<div>
<input class="fijador" type="text" name="fijador"><br>
</div>
<div>
<p></p>
<select class="concentracion" name="dosificacion">
<option value="33">33</option>
<option value="38">38</option>
<option value="50">50</option>
</select>
</div>
<p></p>
<div>
<input class="boton1" type="button" value="dosificacion" onclick="calcular()">
</div>
</form>