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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • 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.