I want to calculate the OHM law (i = v / r) and I have three <input>
and one button with onClick="dividir()"
to call the next function in my HTML:
function dividir() {
v = document.getElementById("voltaje").value;
r = document.getElementById("resistencia").value;
i = v / r;
document.getElementById("corriente").value = i;
};
The function fulfills its purpose but the result value and only appears a few seconds and disappears.
HTML Code:
<div class="container app-contenedor">
<form class="form-inline">
<div class="form-group">
<label>V</label>
<input type="text" class="app-input" id="voltaje"></input>
</div>
<div class="form-group">
<label>R</label>
<input type="text" class="app-input" id="resistencia"></input>
</div>
<div class="form-group">
<label>I</label>
<input type="text" class="app-input" id="corriente"></input>
</div>
<div class="">
<button class="btn app-resultado app-resultado-boton" type="submit" id="calcular" onclick="dividir()">Calcular</button>
</div>
</form>
</div>
How can I let the result be displayed in the text field? or should you create another element that reflects the result of the division instead?