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

109
Vistas
Why alert is coming before entering the message and being added to the firebase?

The moment I enter the username . It gives the alert message that message has been sent before even entering the message and data is being stored in the database with username and empty message . I cannot understand Why ? Can anyone help me with the question . Any help would be appreciated.

const firebaseConfig = {};
firebase.initializeApp(firebaseConfig);
const db = firebase.database();
const username = prompt('Enter your username');

function sendMessage() {

  const messageinput = document.getElementById("messageInput");
  const message2 = messageinput.value;;
  db.ref('User_messages').set({
      "message": message2,
      "username": username
    })
    .then(() => {
      alert('Message sent to the database');
    })
}
document.getElementById('messageBtn').addEventListener('click', sendMessage());
<form id="message-form">
  <input id="messageInput" type="text" placeholder=" Enter Your Doubt Here" />
  <button id="messageBtn" type="submit">Send</button>
</form>
</div>

about 4 years ago · Santiago Gelvez
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