2
I’m cracking my head to make my javascript copy to a new variable the values passed by a form in HTML. Someone could give me a light?
My HTML is like this:
<div class="imc"><!--primeiro container-->
<section class="container">
<h3>Calculadora de Índice de Massa Corporal (IMC).</h3>
<form id="formIMC" onsubmit="calculaImc()">
<!--<form id="formIMC">-->
<label>
Altura:
<input type="text" id="altura" name="altura" maxlenght="5" size="5" autocomplete="off" required>
Peso (kg):
<input type="text" id="peso" name="peso" maxlenght="5" size="5" autocomplete="off" required>
</label>
<br></br>
<!--<button id="calcID" onsubmit="calculaImc()">Calcular</button>-->
<input type="submit" value="Calcular">
</form>
</section><!--Fim do container-->
</div>
And my javascript is like this:
function calculaImc() {
var alturaJS = document.getElementById("altura").getAttribute('altura');
var pesoJS = document.getElementById("peso").getAttribute('peso');
alert (alturaJS + " " + pesoJS);
};
However, my Alert only returns "null null". Does anyone know what’s going on? Or rather, what I’m missing?
Grateful.