Calculation of body mass index (BMI)

1

My html code is as follows:

<!DOCTYPE html PUBLIC "-//WC3//DTD XHTML 1.0 Stric//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>JavaScript Aula 07</title>       
    <script type="text/javascript" src="js/aula07.js"></script>
    <style type="text/css">
    img, table { width:165px; }
    fieldset { width:140px; }
    label { display:block; float:left;}
    label, input {width:68px; margin:3px 0; }
    th, td {border:1px solid #ccc; font-size:0.8em;}
    </style>
</head>
<body>
    <img src="img/imc.png" alt="imc"/>
    <form id="formulario">
        <fieldset>
            <legend>Cálculo do IMC</legend>

            <label for="kilos">Quilos:</label>
            <input type="text" name="quilos"/>          

            <label for="metros">Metros:</label>
            <input type="text" name="metros"/>

            <label for="centimetros">Cm:</label>
            <input type="text" name="centimetros"/>

            <label for="imc">IMC:</label>
            <input type="text" name="imc" disabled="disabled"/>

            <a href="#" onclick="calcularIMC()">Calcular</a>
            </fieldset>
        </form>
    </body>
</html>

And the JavaScript is:

calcularIMC = function (){
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);
}

When using Notepad ++, the HTML page does not seem to be "calling" JavaScript, so no results appear in the IMC field. Thanks to anyone who can help.

    
asked by anonymous 01.08.2014 / 18:41

1 answer

0

Hello, the script loads correctly. However, if you open your browser's console (shortcut: F12 on most of them), you will see that a runtime error occurs, which prevents your function from finishing running.

With the console open, try clicking the calculate button, and you will have clues where your error is.

Just to clarify, you need to switch:

var kilos = +formulario.kilos.value;

By:

var kilos = +formulario.quilos.value;

Hope it helps! Hugs!

    
01.08.2014 / 19:04