Ejs windonw alert always on

stuck with this

always pop ups the alert

this is the code

<% if ( message !== ‘undefined’) { %>

  <div class="container p-4">

    <div class="row">

      <div class="col-md-4 mx-auto">

        <div class="alert alert-danger alert-dismissible fade show" role="alert">

          <%= message %>

          <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>

        </div>

      </div>

    </div>

  </div>

<% } %>

Are you sure this is what you want to test for? There is a difference between the primitive value undefined and the string “undefined”.

Just as an aside, you can use the typeof operator if you want to check for the string ‘undefined’ instead of the undefined primitive value.

let nothing;

nothing !== undefined
// false

nothing !== 'undefined'
// true

typeof nothing !== 'undefined'
// false

code:

¡Bienvenido a Lussona!
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<link rel="stylesheet" href="../Assets/css/login-style.css" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
  href="https://fonts.googleapis.com/css2?family=Open+Sans:wght@300;400;600&display=swap"
  rel="stylesheet"
/>

<link rel="icon" href="/Images/lussona-logo-icon.jpg" />
<div class="login-box">
  <div id="logo-image">
    <img src="../Images/logo-lussona.png" alt="Logo Lussona" class="logo" />
  </div>

  <h1 class="login-title">Inicia Sesión Aquí</h1>

  <form id="login-form" action="/signin" method="post">
    <label for="email">Correo Electrónico</label>
    <input type="email" name="email" placeholder="Introduce tu Correo Electrónico" required/>

    <label for="password">Contraseña</label>
    <input
      type="password" name="password" placeholder="Introduce tu Contraseña" required/>

    <input type="submit" value="Iniciar Sesión" />

    <a id="missing-password" href="/signupView">¿Aún no tiene un usuario? Regístrese</a>
  </form>
</div>


  <div class="container p-4">
    <% if (typeof message !== 'undefined') { %>
    <div class="row">
      <div class="col-md-4 mx-auto">
        <p class="alert alert-danger alert-dismissible fade show" role="alert">
          <%= message %> 
          <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
        </p>
      </div>
    </div>
  </div>
<% } %>

<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM" crossorigin="anonymous"></script>

I merged your threads as they seem related. Please do not open duplicate threads for the same question.

thx, im trying on fixing this

Where is the message variable coming from, where is it declared and assigned a value?

//Global Variables

app.use((req, res, next) => {

app.locals.success = req.flash(“success”);

app.locals.message = req.flash(“message”);

next();

});

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.