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

148
Vistas
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 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