<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport"content="width=device-width, initial-scale=1">
<title>IMC</title>
<head>
<script>
function imc (){
var h, peso, resultado;
resultado = h * 2 / peso;
return imc;
}
window.onload = function(){
document.getElementById("btn");
btn.onclick = function(){
var txt1 = document.getElementById("altura").value;
var txt2 = document.getElementById("peso").value;
var h = document.getElementById(txt1);
var p = document.getElementById(txt2);
document.getElementById("resposta").innerHTML ="<b>Resultado: </b>" + (p / h ^ 2);
}
}
</script>
</head>
<body>
<h2>IMC</h2>
<form name="form1" id="form1" method="post" action="">
Sua altura:
<input name="altura" type="text" id="altura" size="5"><br><br>
Seu peso:
<input name="peso" type="text" id="peso" size="5"><br><br>
<button id="bt" onclick="imc">IMC</button>
<p>IMC: <span id="resposta"></span></p>
</form>
<section>
<button type="button" id="bt" value="Eviar">Limpar</button>
</section>
<article id="res"></article>
</body>
</html>[quote="gustavo_scarpim, post:1, topic:376971, full:true"]
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<meta name="viewport"content="width=device-width, initial-scale=1">
<title>IMC</title>
<head>
<script>
function imc (){
var h, peso, resultado;
resultado = h * 2 / peso;
return imc;
}
window.onload = function(){
document.getElementById("btn");
btn.onclick = function(){
var txt1 = document.getElementById("altura").value;
var txt2 = document.getElementById("peso").value;
var h = document.getElementById(txt1);
var p = document.getElementById(txt2);
document.getElementById("resposta").innerHTML ="<b>Resultado: </b>" + (p / h ^ 2);
}
}
</script>
</head>
<body>
<h2>IMC</h2>
<form name="form1" id="form1" method="post" action="">
Sua altura:
<input name="altura" type="text" id="altura" size="5"><br><br>
Seu peso:
<input name="peso" type="text" id="peso" size="5"><br><br>
<button id="bt" onclick="imc">IMC</button>
<p>IMC: <span id="resposta"></span></p>
</form>
<section>
<button type="button" id="bt" value="Eviar">Limpar</button>
</section>
<article id="res"></article>
</body>
</html>`Texto pré-formatado`
Edite a postagem, selecione todo o código e clique sobre o botão </> acima do editor. Caso contrário, teu código vai ficar impossível de ler.