Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

146
Visualizações
Dissapearing element after function is ran

I'm making a website which welcoms a user with their email, after they log in, but after I submit an email, the heading dissapears, which is supposed to be on the website, which is made from a message and an email.

function logIn() {
        var email = document.getElementById("email").value;
        var password = document.getElementById("password").value;
        var welcomeVar = document.createElement("h1");
        welcomeVar.innerHTML ="Welcome, " + email;
        document.getElementById("Welcome").appendChild(welcomeVar);
}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="index.css">
    <title>Solved! - Home</title>
</head>
<body>
    <div style="text-align: center">
        <img src="logo.png" position="centre">
    </div>
    <form>
        <p>Log in</p>
        <input placeholder="email" id="email"type="email">
        <br>
        <input placeholder="password" id="password" type="password"><br>
        <button onclick="logIn();"><h2>Log in</h2></button>
    </form>
    <form style="text-align: center">
        <input type="text" class="search"placeholder="Type your problem here: ">
        <button><h2>Submit</h2></button>
    </form>
    <div id="Welcome">
    </div>

    
    <script src="index.js"></script>
</body>
</html>

Thanks.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

change your type of button in second form. It will prevent your page from reload and you will get your results.

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="index.css">
    <title>Solved! - Home</title>
</head>

<body>
    
    <div style="text-align: center">
        <img src="logo.png" position="centre">
    </div>
    
    <form>
        <p>Log in</p>
        <input placeholder="email" id="email" type="email">
        <br>
        <input placeholder="password" id="password" type="password"><br>
        <button onclick="logIn();">
            <h2>Log in</h2>
        </button>
    </form>
    
    <form style="text-align: center">
        <input type="text" class="search" placeholder="Type your problem here: ">
        <button type="button">
            <h2>Submit</h2>
        </button>
    </form>
    
    <div id="Welcome"></div>
    
    <script>
    function logIn() {
        let email = document.getElementById("email").value;
        let password = document.getElementById("password").value;
        
        let welcomeVar = document.createElement("h1");
        
        welcomeVar.innerText = `Welcome, ${email}`;
        document.getElementById("Welcome").appendChild(welcomeVar);
    }
    </script>
</body>

</html>
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda