Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

145
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda