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

117
Visualizações
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 à 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