I'm studying Javascript for a YouTube videotape I did the same video, but when I click on Calculate the result appears and already disappears in less than 1 second, when in fact it should stay in the field text.
Below is the html and js. Note: Javascript is in separate file.
<!DOCTYPE html>
<html lang="pt-br">
<head>
<title>Javascript aula 03</title>
<link rel="stylesheet" href="_css/estilo.css">
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="csss/estilo.css">
<script src="js/aula07.js"></script>
</head>
<body>
<img src="imagens/imc.jpg" height="180px" width="200px">
<form id="formulario">
<fieldset style="width:20%;">
<legend>Cálculo do IMC</legend>
<span>
<label for="kilos"> Kilos </label>
<input type="text" name="kilos"><br>
</span>
<span>
<label for="metros"> Metros </label>
<input type="text" name="metros"><br>
</span>
<span>
<label for="centimetros"> Cm </label>
<input type="text" name="centimetros"><br>
</span>
<span>
<label for="imc"> IMC: </label>
<input type="text" name="imc" disabled="disabled"><br>
</span>
<span>
<a href="" onclick="calcularIMC();"> Calcular </a>
</span>
</fieldset>
</form>
</body>
</html>
function calcularIMC() {
var formulario = document.getElementById("formulario");
var kilos = +formulario.kilos.value;
var metros = +formulario.metros.value;
var centimetros = +formulario.centimetros.value;
var altura = (metros * 100 + centimetros) / 100;
var imc = kilos / (altura * altura);
formulario.imc.value = imc;.toFixed(2);
}