Jump to content
Wenderson Lisboa

Problemas com Formulário

Recommended Posts

Wenderson Lisboa

Boa noite amigos, mais uma vez venho solicitar a ajuda de vocês. Estou criando um aplicativo simples num site: preciso pegar um dado no input e exibi-lo numa TAG <p> usando o getElementById(). estou conseguindo mas na hora de mostrar o resultado ele simplesmente some rapidamente. Por favor me ajudem.

<!DOCTYPE html>

<html lang="pt-br">

<head>

       <meta charset="UTF-8">

       <title>Document</title>

       <script>

                       function imc(){

                                  var alt = document.getElementById("altura").value;

                                  var pes = document.getElementById("peso").value;

                                  var mult = (alt * alt);

                                  var res = (pes / mult).toFixed(2);

                                  document.getElementById("resposta").innerHTML = `Seu IMC é : ${res}`;

                      }

</script>

</head>

<body>

         <form>

                <input type="text" id="peso"/><br>

                <input type="text" id="altura"/>

                <button onclick="imc()">Calcular</button>

                <p id="resposta"></p>

         </form>

</body>

</html>

 

Edited by thoga31
GeSHi

Share this post


Link to post
Share on other sites
Wenderson Lisboa
21 minutos atrás, Zex disse:

Basta tirar <form> e </form>

Muito obrigado, estou iniciando do zero.

Edited by Wenderson Lisboa

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.