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

150
Visualizações
I need help getting a javascript function to execute in correct order

I am having trouble grasping how to make this bit of code execute in the correct order:

window.writeData=function() {
  console.log('this works.');
  push(ref(db), {
          First_Name: document.getElementById("firstname").value,
          Last_Name: document.getElementById("lastname").value,
          Street: document.getElementById("street").value,
          City: document.getElementById("city").value,
          State: document.getElementById("state").value,
          Zip: document.getElementById("zip").value,
      }

  );
  window.location.href = 'calendar.html';}

What's suppose to happen is when a button with onclick="writeData() is pressed the various values gets written to the database and then the calendar.html page is loaded. However, as it is right now no data is being pushed to the database. I'm assuming its because the window.location.href = 'calendar.html'; is being executed first.

How do I prevent this? I've been trying to figure out if callback() or setTimeout() is the way to go, but I can't get anything to work properly.

about 4 years ago · Juan Pablo Isaza
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